Egg Drop With 2 Eggs and N Floors - Problem
You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.
You know that there exists a floor f where 0 ≤ f ≤ n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.
In each move, you may take an unbroken egg and drop it from any floor x (where 1 ≤ x ≤ n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.
Return the minimum number of moves that you need to determine with certainty what the value of f is.
Input & Output
Example 1 — Small Building
$
Input:
n = 2
›
Output:
2
💡 Note:
Drop first egg from floor 1. If it breaks, critical floor is 0 (2 moves). If it doesn't break, drop from floor 2. If it breaks, critical floor is 1, otherwise critical floor is 2 (2 moves total).
Example 2 — Medium Building
$
Input:
n = 10
›
Output:
4
💡 Note:
Using optimal strategy: drop from floors 4, 7, 9, 10. This guarantees finding the critical floor in at most 4 moves regardless of where it is.
Example 3 — Single Floor
$
Input:
n = 1
›
Output:
1
💡 Note:
Only one floor to test. Drop the egg from floor 1. If it breaks, critical floor is 0, otherwise it's 1. Only 1 move needed.
Constraints
- 1 ≤ n ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Building with n floors, 2 identical eggs
2
Process
Strategic dropping to minimize worst-case moves
3
Output
Minimum moves to guarantee finding critical floor f
Key Takeaway
🎯 Key Insight: Balance worst-case outcomes by using triangular number formula
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code