Super Egg Drop

You are given k 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.

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.

Example 1
Inputk = 1, n = 2
Output2
By dropping from floor 1 and then floor 2 if needed, 2 moves are necessary and sufficient to determine f with certainty.
Example 2
Inputk = 2, n = 6
Output3
With 2 eggs and 6 floors, the minimum number of moves needed to determine f with certainty is 3.

Constraints

  • 1 <= k <= 100
  • 1 <= n <= 10^4

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate