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
What is difference between scanf and gets?
What is call by value in c?
What is the difference between typedef and #define?
How to establish connection with oracle database software from c language?
How can I prevent another program from modifying part of a file that I am modifying?
What are the different types of pointers used in c language?
What is a lvalue
Can we increase size of array in c?
List the variables are used for writing doubly linked list program.
Why calloc is better than malloc?
Are bit fields portable?
What is variables in c?
Why enum is used in c?
What is meant by errors and debugging?
How can I find out how much free space is available on disk?