Quant Memo
Core

The Egg Drop With k Eggs and n Floors

The classic two-egg drop puzzle generalizes to any number of eggs, and the trick that solves it is thinking in terms of how many drops guarantee finding the answer, not how many floors you can search.

The familiar version of this puzzle gives you two eggs and a 100-floor building, and asks for the minimum number of drops that guarantees finding the highest floor an egg survives falling from, in the worst case. The general version replaces "two eggs" with kk eggs and asks the same question. Naively, more eggs should make the answer harder to compute, but the trick that cracks the two-egg case scales cleanly to any kk.

The key reframe: instead of asking "with kk eggs and a budget of dd drops, how many floors can I test?", flip it around and ask "with kk eggs and dd drops, what is the maximum number of floors I can definitively resolve?" Define f(d,k)f(d, k) as that maximum. A single drop either breaks the egg (leaving k1k-1 eggs and d1d-1 drops to search below) or doesn't (leaving kk eggs and d1d-1 drops to search above), plus the one floor just tested. That gives the recurrence

f(d,k)=f(d1,k1)+f(d1,k)+1f(d, k) = f(d-1, k-1) + f(d-1, k) + 1

with f(d,1)=df(d, 1) = d (one egg forces a linear floor-by-floor search) and f(0,k)=0f(0, k) = 0. The answer to "minimum drops needed for nn floors and kk eggs" is the smallest dd with f(d,k)nf(d, k) \ge n.

For k=2k = 2 eggs and n=100n = 100 floors: building up f(d,2)f(d, 2) for d=1,2,d = 1, 2, \dots gives 2,5,9,14,2, 5, 9, 14, \dots following f(d,2)=f(d1,1)+f(d1,2)+1f(d,2) = f(d-1,1) + f(d-1,2) + 1, and it first reaches 100 at d=14d = 14 — the well-known answer to the original puzzle.

Reframe "how many floors can I search" as "how many floors can dd drops and kk eggs definitively resolve," and the recurrence f(d,k)=f(d1,k1)+f(d1,k)+1f(d,k) = f(d-1,k-1) + f(d-1,k) + 1 solves any number of eggs, not just two.

Related concepts

Practice in interviews

Further reading

  • Classic CS interview puzzle, generalized k-egg version
ShareTwitterLinkedIn