Description
Koko loves bananas. There are n piles of bananas, the ith pile has piles[i] bananas. Guards will return in h hours. Koko can eat at most k bananas per hour. If a pile has less than k bananas, she finishes that pile and won't eat more in that hour. Return the minimum integer k such that she can eat all bananas within h hours.
Examples
piles = [3,6,7,11], h = 84At eating speed 4: pile of 3 takes 1 hour, pile of 6 takes 2 hours, pile of 7 takes 2 hours, pile of 11 takes 3 hours, totaling 8 hours which equals h=8. Speed 4 is the minimum that finishes within 8 hours.
piles = [30,11,23,4,20], h = 530She must finish each pile in 1 hour, so k = max(piles) = 30.
piles = [2,2,2,2], h = 62With k=2, Koko can eat each pile in exactly 1 hour: ceil(2/2) = 1 hour per pile. Total time = 1+1+1+1 = 4 hours, which is ≤ 6 hours. With k=1, she would need ceil(2/1) = 2 hours per pile, totaling 8 hours > 6. Therefore, minimum k = 2.
Constraints
- •
1 ≤ piles.length ≤ 10⁴ - •
piles.length ≤ h ≤ 10⁹ - •
1 ≤ piles[i] ≤ 10⁹