Two-Egg Dropping
Problem statement
A building has floors 1 through n and an unknown highest safe floor f, where 0 <= f <= n. You have two identical eggs. A drop above f breaks the egg; a drop at or below f leaves it reusable. A broken egg cannot be used again.
Choose each drop based on previous outcomes. Return the smallest number of drops that guarantees you can determine f in the worst case.
Function
twoEggDrop(n: int) → intExamples
Example 1
n = 1return = 1One drop distinguishes highest safe floor 0 from 1.
Example 2
n = 6return = 3Start at floor 3, then 5, then 6 if the first egg survives. If it breaks, linearly check the remaining lower floors with the second egg; at most three drops are needed.
Example 3
n = 50return = 10Nine drops can cover at most 45 floors; ten drops can cover 55.
Constraints
1 <= n <= 1000.- Drop outcomes follow one fixed threshold and are deterministic.