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


Please Help Members By Posting Answers For Below Questions

What is difference between scanf and gets?

616


What is call by value in c?

563


What is the difference between typedef and #define?

552


How to establish connection with oracle database software from c language?

1679


How can I prevent another program from modifying part of a file that I am modifying?

618






What are the different types of pointers used in c language?

614


What is a lvalue

668


Can we increase size of array in c?

544


List the variables are used for writing doubly linked list program.

1626


Why calloc is better than malloc?

574


Are bit fields portable?

681


What is variables in c?

611


Why enum is used in c?

530


What is meant by errors and debugging?

651


How can I find out how much free space is available on disk?

632