hard +45 pts

Egg Drop Puzzle

Find the minimum number of trials needed to determine the critical floor with k eggs and n floors.

You are given `k` eggs and a building with `n` floors (numbered 1 to n). There exists a critical floor `f` (0 <= f <= n) such that eggs dropped from floors <= f do not break, and eggs dropped from floors > f break. You need to determine the exact value of `f` in the worst case with the fewest number of egg drops. Implement the function `min_drops(k: int, n: int) -> int` that returns the minimum number of drops required to guarantee finding the critical floor. **Rules:** - An egg that survives a drop can be reused. - An egg that breaks is discarded and cannot be reused. - You have at most `k` eggs initially. - If you have only one egg, you must test floors sequentially from lowest to highest (worst-case drops = n). - If you have unlimited eggs, the problem reduces to binary search, but with limited eggs you must balance. **Input:** Two integers `k` and `n`, where `1 <= k <= 100` and `1 <= n <= 10000`. Both are within these bounds. The answer fits in a 32-bit integer. **Output:** An integer representing the minimum number of drops needed in the worst case. **Complexity:** Your solution should be efficient for the given bounds. An O(k n) dynamic programming approach is acceptable.

Constraints

1 <= k <= 100, 1 <= n <= 10000. The answer fits in a 32-bit integer. Time complexity should be reasonable (O(k n) or better).

Example

>>> min_drops(1, 2)
2
>>> min_drops(2, 6)
3
>>> min_drops(3, 14)
4
>>> min_drops(2, 100)
14
45 points ~35 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Think of the state as (eggs, floors) and try to minimize the worst-case drops by choosing a drop floor optimally.
The recurrence is: min over x from 1 to N of 1 + max(dp[eggs-1][x-1], dp[eggs][N-x]).
Optimize by using a 2D DP table and iterating over floors carefully.
Alternative: invert the problem — compute the maximum floors testable with given drops and eggs using dp[m][k] = dp[m-1][k-1] + dp[m-1][k] + 1.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.