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.
2026 Update: Egg Drop — DP Classic with Real-World Applications
The egg drop problem: given n eggs and k floors, find the minimum number of trials needed to determine the critical floor (above which eggs break). This is a fundamental dynamic programming problem with multiple solution approaches.
import math
from functools import lru_cache
# Approach 1: Classic DP — O(nk^2)
def egg_drop_dp(n_eggs, k_floors):
"""Min trials to find critical floor with n eggs and k floors."""
# dp[e][f] = min trials with e eggs and f floors
dp = [[0] * (k_floors + 1) for _ in range(n_eggs + 1)]
for e in range(1, n_eggs + 1):
for f in range(1, k_floors + 1):
if e == 1:
dp[e][f] = f # Linear search with 1 egg
else:
dp[e][f] = float('inf')
for floor in range(1, f + 1):
# Egg breaks: check below (e-1 eggs, floor-1 floors)
# Egg survives: check above (e eggs, f-floor floors)
worst = 1 + max(dp[e-1][floor-1], dp[e][f-floor])
dp[e][f] = min(dp[e][f], worst)
return dp[n_eggs][k_floors]
# Approach 2: Mathematical — O(n * answer) using reverse problem
def egg_drop_math(n_eggs, k_floors):
"""
Reverse: given n eggs and t trials, what's max floors we can check?
f(t, n) = f(t-1, n-1) + 1 + f(t-1, n)
Find min t such that f(t, n) >= k.
"""
# f(t, n) = C(t,1) + C(t,2) + ... + C(t,n)
t = 0
while True:
t += 1
floors_covered = sum(math.comb(t, i) for i in range(1, n_eggs + 1))
if floors_covered >= k_floors:
return t
# Both should give same answer
print(egg_drop_dp(2, 100)) # 14
print(egg_drop_math(2, 100)) # 14
# With 2 eggs, 100 floors: try floors 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100
# Pattern: 14, 13, 12, 11, ... (decreasing intervals)
def optimal_floors_2eggs(k=100):
t = egg_drop_math(2, k)
floors = []
f = 0
for drop in range(t, 0, -1):
f += drop
if f <= k:
floors.append(f)
return floors[:t]
print(optimal_floors_2eggs()) # [14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99]
Real-world mappings:
- Binary search with limited retries: API rate limits with exponential backoff
- A/B testing rollouts: finding the threshold (e.g., traffic %) where a feature degrades, with limited ability to roll back
- Load testing: finding the server capacity limit with limited test runs before overload
Time complexity: O(nk²) for basic DP; O(n log k) with binary search optimization; O(n × answer) for the mathematical approach. LeetCode #887.
💡Strategies for Solving This Problem
The Egg Drop Problem
Classic DP problem that showed up at Microsoft in 2023. It's about minimizing worst-case attempts, not average case. That trips people up.
The Problem
You have k eggs and a building with n floors. Find the minimum number of drops needed to find the critical floor (highest floor from which an egg won't break) in the worst case.
Understanding the Problem
Key constraints:
- If an egg breaks, you can't reuse it
- If it doesn't break, you can drop it again
- Need to find the threshold floor
- Minimize worst-case drops, not average
Approach 1: Two Eggs, Linear Scan
With 2 eggs and 100 floors, you might think: drop from floor 10, 20, 30... If it breaks at 30, go back and try 21, 22, 23...
Worst case: First egg breaks at 100 (10 drops), then 9 more drops. Total: 19 drops.
But we can do better.
Approach 2: Two Eggs, Optimal
Use decreasing intervals! Start at floor 14. If it breaks, check floors 1-13 (13 drops). If it doesn't break, go to floor 27 (14+13). If it breaks there, check floors 15-26 (12 drops).
Pattern: 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100
Worst case: 14 drops for 100 floors.
Why? First drop + remaining floors should equal worst case constant.
General Solution: Dynamic Programming
For k eggs and n floors, use DP:
dp[k][n] = minimum drops needed with k eggs and n floors
Recurrence:
dp[k][n] = 1 + min(
max(dp[k-1][x-1], dp[k][n-x])
) for all x from 1 to n
If we drop from floor x:
- Egg breaks: Check floors 1 to x-1 with k-1 eggs
- Egg survives: Check floors x+1 to n with k eggs
- Take max (worst case), minimize over all x
At Microsoft
Started with the 2-egg solution. Interviewer asked "What if you have unlimited eggs?" Answer: Binary search, log n drops. Then asked for general solution - that's when I pulled out DP.