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 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 .
The key reframe: instead of asking "with eggs and a budget of drops, how many floors can I test?", flip it around and ask "with eggs and drops, what is the maximum number of floors I can definitively resolve?" Define as that maximum. A single drop either breaks the egg (leaving eggs and drops to search below) or doesn't (leaving eggs and drops to search above), plus the one floor just tested. That gives the recurrence
with (one egg forces a linear floor-by-floor search) and . The answer to "minimum drops needed for floors and eggs" is the smallest with .
For eggs and floors: building up for gives following , and it first reaches 100 at — the well-known answer to the original puzzle.
Reframe "how many floors can I search" as "how many floors can drops and eggs definitively resolve," and the recurrence solves any number of eggs, not just two.
Related concepts
Practice in interviews
Further reading
- Classic CS interview puzzle, generalized k-egg version