Find the minimum integer eating speed that lets Koko finish all banana piles within hours.
Koko has several piles of bananas. In each hour, she chooses one pile and eats bananas from that pile at a fixed integer speed bananas per hour.
If a pile has fewer than bananas, she eats the whole pile in that hour. Koko cannot split an hour across multiple piles.
Given the array of pile sizes and a limit of hours, determine the minimum integer speed such that Koko can finish all bananas within hours.
Return the smallest positive integer speed that makes the total time required less than or equal to .
piles, where piles[i] is the number of bananas in the -th pile.h, the maximum number of hours available.k.1 <= piles.length1 <= piles[i]1 <= hk, the required hours for one pile is .Example 1
Input
piles = [3, 6, 7, 11], h = 8
Output
4
Explanation
At speed 4, the time needed is . No smaller speed can finish in 8 hours.
Example 2
Input
piles = [30, 11, 23, 4, 20], h = 5
Output
30
Explanation
Koko must finish one pile per hour, so she needs a speed large enough to eat the largest pile in one hour. The minimum such speed is 30.
Example 3
Input
piles = [30, 11, 23, 4, 20], h = 6
Output
23
Explanation
At speed 23, the hours are . Any smaller speed requires more than 6 hours.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.