> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Super Egg Drop Python Solution with Tests

> Tested Python solution for LeetCode 887 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 887, [Hard](/catalog/hard). Topics: [Math](/catalog/topics/math), [Binary Search](/catalog/topics/binary-search), [Dynamic Programming](/catalog/topics/dynamic-programming). [View on LeetCode](https://leetcode.com/problems/super-egg-drop/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 887   # by problem number
lcpy gen -s super_egg_drop   # by problem name
```

## Problem

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*.

### Examples

```
Input: k = 1, n = 2
Output: 2
Explanation:
Drop the egg from floor 1. If it breaks, we know that f = 0.
Otherwise, drop the egg from floor 2. If it breaks, we know that f = 1.
If it does not break, then we know f = 2.
Hence, we need at minimum 2 moves to determine with certainty what the value of f is.
```

```
Input: k = 2, n = 6
Output: 3
```

```
Input: k = 3, n = 14
Output: 4
```

### Constraints

* 1 \<= k \<= 100
* 1 \<= n \<= 10^4

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/super_egg_drop/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/super_egg_drop/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(k * moves) where moves is the answer (moves <= n)
    # Space: O(k)
    def super_egg_drop(self, k: int, n: int) -> int:
        # coverage[i] = number of floors distinguishable with i eggs in the
        # current number of moves: coverage[i] = coverage[i] + coverage[i-1] + 1
        coverage = [0] * (k + 1)
        moves = 0
        while coverage[k] < n:
            moves += 1
            for eggs in range(k, 0, -1):
                coverage[eggs] += coverage[eggs - 1] + 1
        return moves
```

## Complexity

| Time | Space |
| - | - |
| O(k \* moves) where moves is the answer (moves \<= n) | O(k) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.