Question: You have two identical eggs. Standing in front of a 100 floor building, you wonder what is the maximum number of floors from which the egg can be dropped without breaking it. What is the minimum number of tries needed to find out the solution?
Answer: The easiest way to do this would be to start from the first floor and drop the egg. If it doesn’t break, move on to the next floor. If it does break, then we know the maximum floor the egg will survive is 0. If we continue this process, we will easily find out the maximum floors the egg will survive with just one egg. So the maximum number of tries is 100 that is when the egg survives even at the 100th floor.
Can we do better? Of course we can. Let’s start at the second floor. If the egg breaks, then we can use the second egg to go back to the first floor and try again. If it does not break, then we can go ahead and try on the 4th floor (in multiples of 2). If it ever breaks, say at floor x, then we know it survived floor x-2. That leaves us with just floor x-1 to try with the second egg. So what is the maximum number of tries possible? It occurs when the egg survives 98 or 99 floors. It will take 50 tries to reach floor 100 and one more egg to try on the 99th floor so the total is 51 tries. Wow, that is almost half of what we had last time.
Can we do even better? Yes we can (Bob, the builder). What if we try at intervals of 3? Applying the same logic as the previous case, we need a max of 35 tries to find out the information (33 tries to reach 99th floor and 2 more on 97th and 98th floor).
Interval – Maximum tries
1 – 100
2 – 51
3 – 35
4 – 29
5 – 25
6 – 21
7 – 20
8 – 19
9 – 19
10 – 19
11 – 19
12 – 19
13 – 19
14 – 20
15 – 20
16 – 21
So picking any one of the intervals with 19 maximum tries would be fine.
Update: Thanks to RiderOfGiraffes for this solution.
Instead of taking equal intervals, we can increase the number of floors by one less than the previous increment. For example, let’s first try at floor 14. If it breaks, then we need 13 more tries to find the solution. If it doesn’t break, then we should try floor 27 (14 + 13). If it breaks, we need 12 more tries to find the solution. So the initial 2 tries plus the additional 12 tries would still be 14 tries in total. If it doesn’t break, we can try 39 (27 + 12) and so on. Using 14 as the initial floor, we can reach up to floor 105 (14 + 13 + 12 + … + 1) before we need more than 14 tries. Since we only need to cover 100 floors, 14 tries is sufficient to find the solution.
Therefore, 14 is the least number of tries to find out the solution.
If you have any questions, please feel free to send me an email at support@mytechinterviews.com. If you have any interview questions which you feel would benefit others, I would love to hear about it.
Related posts:


OK, so now you know it can be done in 19 tries, let’s see if it can be done in fewer. Let’s go for 18.
That means I can first drop the egg from the 18th floor and if it breaks, try 1 through 17. If it doesn’t break then I’ve used one attempt and I’m allowed 17 more.
Let’s try the 35th floor. If it breaks then I can try 19 through 34, again a maximum of 18 (2 already plus another 16). If it doesn’t break then I’ve used two attempts and I’m allowed 16 more.
Continuing like this I can get up to 171, and spotting that pattern shows that 171 is 18x(18+1)/1, or the sum of numbers 1 through 18.
OK, so I should be able to get 100 floors with a starting value of 14. 14x(14+1)/2 = 105, and a check check shows I can do that.
So I can do it in 14, which I’m pretty sure is less than your 19. Given that you asked:
What is the minimum number of tries
needed to find that information?
Actually, rather than the “double up till you exceed your desired value” strategy you should use “divide and conquer.”
Let’s drop the egg from the 50th floor. Whether it breaks or not we can use the other egg to cover the half we want, so using at most 1+50 tests.
But the two halves aren’t equal, because if it doesn’t break we can use it again in the top half, dropping it from 75. Perhaps we should start with dropping it from 33, then if it breaks fill the gap, and if it doesn’t, recurse in the top portion.
So what fraction should we go up? Overviously 50% is too much, is there a nice ratio? Can we prove it?
A good guess in these cases is the Golden Section, in this case something like 1/phi or 0.618034. So perhaps we should go up 38 floors, leaving 62 above.
Another good guess would use 1/e, or the 37th floor. That seems to big. In either case, it’s not hard to push through this analysis.
Final comment. The asymmetry is more severe in the attempt to recurse than just the egg broken or not. We’ve already used a drop when we go to the top half, so the recursion isn’t straight-forward, and the optimal solution is the one I first gave.
What if the eggs can survive in 2 storey. using the method with interval of 1 you needs 3 tries,but using the method with interval of 8 needs 4 tries. likewise if the egg can survive in 5 storey.using the method with interval of 3 need 4 tries ,but using the method with interval of 8 you need 7 tries.maybe some other factors should consider, like probability.
Yes RiderOfGiraffes, recursively making the intervals half is not going to work. You first is better though.
I am sorry didxga, I do not quite understand what you are trying to explain. Could you try explaining it in a little more detail. Thanks.
Aswin,Sorry for my poor english. i just want to point out that using the initial solution can not always produce the optimal result.I have provided two cases when eggs survive in 2 or 5 floor to explain it
I guess I would have “failed” on this interview question.
My answer would be Zero. All the extra information seems designed to obfuscate the problem.
The minimum number would imho be 1 because if you are very lucky it breaks already on the first floor
I think 7 tries should be enough.
With n floors we have n+1 possible outcomes. n floors + 0 (the egg always breaks).
We know that if the egg doesn’t break when dropped from floor X the answer will be either equal or larger then X. If the egg breaks the answer will be smaller then X.
Let’s start at the 1/2*n floor and drop the egg.
If it breaks the maximum floor is below 1/2*n, if it doesn’t break the floor is above 1/2*n. Now we simply repeat the drop at 1/2*n + 1/4*n or at 1/4*n. This way we half the solution area with every try.
100 can be divided by two 7 times until we get 1. Or said differently, we’re looking for the smallest y in the following equation: 2 ^ y >= n.
Now what will happen if the egg breaks at floor 50 and then it breaks again at floor 25. You are out of eggs as well as luck. You will not be able to identify which floor is the maximum.
yeah, i noticed i miss read the 2 eggs part. heh, eggs are always in plenty stock where i’m from
I really dislike puzzles like this. An egg that survived a drop would be weakened. Information about subsequent drops would be useless without knowledge of how the eggs are affected by previous drops.
Call me a pedant, but if you aren’t supposed to consider this then what else aren’t you supposed to consider?
general formula for it is
F(b, d)=F(b-1, d-1)+F(b, d-1)+1
where F(b, d) is number of floors such that if you are given b number of balls, d number of drops and f100
d=14
u got 2 eggs.. so only 2 chances.. lol
In addition to the valid point about weakening, this is the type of test where (as an interviewer) I would want to hear something like “common knowledge would seem to indicate that an egg will not survive a fall of even one story. eggs break when you jostle the carton, let alone when you drop them 10 or 20 feet. so any testing regime would begin with a sanity check – drop it from the minimum distance to verify that our common-sense assumption of immediate breakage is in fact right.”
John Leach’s comment is good, but really we don’t have to drop the egg at all. Has NO ONE at Google ever dropped an egg from a counter and had it break? Dropping an egg from multiple stories is ridiculous!
Yes, coming up with mathematical answers is important. Knowing what questions are worth asking is more so.
(Okay, wise guy, so now we’re going to drop an experimental ball and want to know when it breaks. Happy now?)
Yes, but John Leach still applies.
if you ONLY have 2 eggs then there’s no better solution than 51 tries.
couldn’t the minimum number of tries just be 1? you could get lucky and pick the correct floor first… I know this isn’t a mathematical proof, but it is definitely possible that someone figures this out in 1 try.
Toshiro, what would you do if the first egg doesn’t break on the 50th floor?
We want a guaranteed answer at the end of the tries. This is not possible with just one try.
First try at 100th floor it it breaks then try in 100/2=50th floor if it didnt break then try in 75th floor else 25th floor. Continue above steps.
What if your egg breaks on the 100th floor and the 50th floor. You won’t have any more eggs to try with. This won’t solve the problem.