Koko Eating Bananas
An eater chooses an integer speed k. During each hour they eat up to k bananas from one pile, finishing that pile or leaving its remainder; unused time cannot be spent on another pile. Return the smallest speed that finishes within h hours.
Example 1
piles = [4,7,9]
h = 64Explanation
Speed 4 needs 1+2+3=6 hours; speed 3 needs 8, so 4 is minimal.
Example 2
piles = [9,3]
h = 29Explanation
Two hours for two piles means each must finish in one hour, requiring speed 9.
Example 3
piles = [5]
h = 71Explanation
Speed 1 finishes five bananas within seven hours and is the smallest positive speed.
Constraints
- 1 <= len(piles) <= 10000
- len(piles) <= h <= 1000000000
- Piles are 1..1000000000
Function contract
minEatingSpeedArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[4,7,9]6