There is a 100-story building and you are given two eggs.
The eggs (and the building) have an interesting property
that if you throw the egg from a floor number less than X,
it will not break. And it will always brake if the floor
number is equal or greater than X. Assuming that you can
reuse the eggs which didn't broke; you got to find X in a
minimal number of throws. Give an algorithm to find X in
minimal number of throws.
Answer Posted / j1g54w h4ck3r
Find a number n such that n(n+1)/2>=99. (You'll know why
later). n=14 in this case.
Throw one egg from 14th floor.
If it breaks,
start throwing the other egg starting from the 1st floor,
bottom up till it breaks. Max no of throws(worst case)=1+13=14.
else Throw the egg from (14+13)= 27th floor. If it breaks
start throwing the other egg from 15th floor bottom up. Max
no of throws=2+12=14.
Continue till you find the floor.
In the worst case, you'll have to do 14trials compared to
the rather large figures provided by other solutions.
Regards,
J1g54w H4ck3r
| Is This Answer Correct ? | 71 Yes | 11 No |
Post New Answer View All Answers
How can I prevent another program from modifying part of a file that I am modifying?
Write a program to print factorial of given number without using recursion?
Explain how can you determine the size of an allocated portion of memory?
what is a constant pointer in C
Are there any problems with performing mathematical operations on different variable types?
How can you avoid including a header more than once?
What is 1d array in c?
What are the applications of c language?
When should we use pointers in a c program?
code for quick sort?
What is malloc() function?
Tell me when is a void pointer used?
What does a pointer variable always consist of?
How can a process change an environment variable in its caller?
What do you mean by Recursion Function?