Super Egg Drop
HardP3Coding
You have k identical eggs and a building with floors 1..n. There is an unknown critical floor f (0 <= f <= n): an egg dropped from a floor above f breaks, and from floor f or below it survives. A surviving egg can be dropped again; a broken egg is gone.
Return the minimum number of drops that guarantees you find f in the worst case.
Example 1
- Input
- k = 1, n = 2
- Output
- 2
- Why
- Drop from floor 1; if it survives, drop from floor 2. Two drops in the worst case.
Example 2
- Input
- k = 2, n = 6
- Output
- 3
- Why
- Drop from floor 3 first; then use the second egg floor by floor if it breaks, or go higher if it survives.
Example 3
- Input
- k = 3, n = 14
- Output
- 4
Constraints
- 1 <= k <= 100
- 1 <= n <= 10^4
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 12. ⌘Enter runs, ⌘⇧Enter submits.