Class Solution
- java.lang.Object
-
- g0801_0900.s0887_super_egg_drop.Solution
-
public class Solution extends Object
887 - Super Egg Drop.Hard
You are given
kidentical eggs and you have access to a building withnfloors labeled from1ton.You know that there exists a floor
fwhere0 <= f <= nsuch that any egg dropped at a floor higher thanfwill break , and any egg dropped at or below floorfwill not break.Each move, you may take an unbroken egg and drop it from any floor
x(where1 <= 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
fis.Example 1:
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.
Example 2:
Input: k = 2, n = 6
Output: 3
Example 3:
Input: k = 3, n = 14
Output: 4
Constraints:
1 <= k <= 1001 <= n <= 104
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intsuperEggDrop(int k, int n)
-