Skip to main content
Back to ChallengesEgg Dropping PuzzleHard 40 min

Egg Dropping Puzzle

You are given k identical eggs and a building with n floors. Determine the minimum number of moves that you need to find the critical floor f with certainty.

Examples

Input: k = 2, n = 6
Output: 3
Drop first egg from floor 3. If breaks, test 1 and 2. Else drop from 5, etc.

Constraints

  • 1 <= k <= 100
  • 1 <= n <= 10000

Complexity Analysis

Time
O(k * m)
where m is the minimum number of attempts.
Space
O(k * m)
DP array storing max reachable floors for (moves, eggs).

Test Cases

#1 2 eggs, 6 floors
Input: 2, 6
Expected: 3
#2 3 eggs, 14 floors
Input: 3, 14
Expected: 4
#3 1 egg, 2 floors
Input: 1, 2
Expected: 2
JavaScript
Output
Click "Run Code" to see output here...