Koko Eating Bananas
MediumP1Coding
There are piles[i] bananas in the i-th pile. Koko eats at a speed of k bananas per hour. Each hour she picks one pile and eats up to k bananas from it; if the pile has fewer than k, she finishes it and waits out the rest of the hour. She must finish all piles within h hours.
Return the smallest integer speed k that lets her finish in at most h hours.
Example 1
- Input
- piles = [3,6,7,11], h = 8
- Output
- 4
Example 2
- Input
- piles = [30,11,23,4,20], h = 5
- Output
- 30
- Why
- With five piles and five hours, she needs one hour per pile, so k = max pile.
Example 3
- Input
- piles = [30,11,23,4,20], h = 6
- Output
- 23
Constraints
- 1 <= piles.length <= 10^4
- piles.length <= h <= 10^9
- 1 <= piles[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.