Then you may be thinking of dropping the first egg at 25th floor, then at 50th, 75th etc, this will take 28 tries if the answer is 99th floor.
There is definitely a better answer.
The optimal number of drops would be such that if you do the first drop from nth floor, if the attempt fails, then do the drop by climbing (n-1) more floors, if it fails again, then do the drop after climbing (n-2) floors etc till (n-x) = 1. At this point you should have covered all the floors.
If the drop at any of these point breaks the egg, then start dropping from the last floor at which the breakage did not happen with the second egg and move up. In this way, n drops would be what you require the maximum to figure out the breaking point in any scenario.
So, in our case, to cover up 100 floors:
n + (n-1) + (n-2) + (n-3) + ......+ 2 + 1 >= 100
i.e, n*(n+1)/2 >= 100
=> n = 14
So, 14 is the answer.
one example sequence - 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99 (let's say it broke at 99), 96, 97, 98 => 14 iterations.
No comments:
Post a Comment