You have k identical eggs and a building with n floors labeled 1 to n.
There is an unknown floor f with 0 <= f <= n. An egg dropped from any floor higher than f breaks, and an egg dropped from floor f or lower does not break.
In each move you take an unbroken egg and drop it from any floor x with 1 <= x <= n. A broken egg cannot be used again. An egg that survives can be reused in later moves.
Return the minimum number of moves you need to determine the value of f with certainty.
Function Signature
def egg_drop_min_moves(k: int, n: int) -> int:
Rules
-
"With certainty" means the strategy must identify
f
for every possible value from
0
to
n
. The answer is the number of moves the best strategy needs in its worst case.
-
A strategy may choose each floor based on the results of earlier drops.
Constraints
-
1 <= k <= 100
-
1 <= n <= 10^4
Examples
Input: k = 1, n = 2
Output: 2
With one egg you have to test from the bottom up: drop from floor 1, and if the egg survives, drop from floor 2. One move cannot work, because a single drop has two outcomes and f can be 0, 1 or 2.
Input: k = 2, n = 6
Output: 3
Drop first from floor 3. If the egg breaks, test floor 1 and then floor 2 with the other egg; if it survives, drop from floor 5 and then from floor 4 or floor 6. Two moves are not enough, since two drops give at most four outcomes and f has seven possible values.
Input: k = 3, n = 14
Output: 4
Three drops give at most eight outcomes, fewer than the 15 possible values of f, so three moves cannot work. A strategy that starts at floor 7 always finishes in four moves.