Koko Eating Bananas
Koko has n piles of bananas, where piles[i] is the count in the i-th pile, and the guards return in h hours. Each hour Koko picks one pile and eats up to k bananas from it; if the pile has fewer than k she finishes it and stops for that hour. Return the minimum integer eating speed k so she can finish all bananas within h hours.
Open official problem prompt ↗Find the slowest constant eating speed that still clears every pile within the allotted hours.
Like tuning a shower knob to the lowest flow that still fills the tub before your alarm rings: turn it up when you are behind, ease it down when you have spare time, converging on the exact threshold.
- Input
- piles = [3, 6, 7, 11], h = 8
- Output
- 4
- Why
- At speed 4 the hours are ceil(3/4)+ceil(6/4)+ceil(7/4)+ceil(11/4) = 1+2+2+3 = 8, which fits in h; speed 3 would need 9 hours.
1 <= piles.length <= 10^4piles.length <= h <= 10^91 <= piles[i] <= 10^9