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 function prototype?
application attempts to perform an operation?
What are enumerated types?
Why main function is special give two reasons?
What is null in c?
What are the advantages and disadvantages of a heap?
What is self-referential structure in c programming?
What is the purpose of void in c?
Are there namespaces in c?
Is linux written in c?
What is volatile variable how do you declare it?
What is the size of empty structure in c?
Tell me what is null pointer in c?
When should volatile modifier be used?
find out largest elemant of diagonalmatrix