Koko has n banana piles, with piles[i] bananas in the i-th pile. The guards are away now and are expected back after h hours.
She selects a constant eating rate of k bananas per hour. During each hour, she picks one pile and eats up to k bananas from it. If that pile contains fewer than k bananas, she finishes the pile and spends the rest of that hour eating nothing.
Koko prefers the smallest possible rate, provided that every banana is eaten no later than the guards’ return.
Return the minimum integer k that lets Koko finish all piles within h hours.
Example 1:
Input: piles = [3,6,7,11], h = 8
Output: 4
Explanation:
At k = 4, the required time is ceil(3/4) + ceil(6/4) + ceil(7/4) + ceil(11/4) = 1+2+2+3 = 8 hours, which meets the deadline.
piles = [3,6, 7, 11] h = 8
4
We have 4 banana piles: [3, 6, 7, 11] and Koko must finish within h = 8 hours.
Example 2:
Input: piles = [30,11,23,4,20], h = 5
Output: 30
Explanation:
There are five piles and only five hours, so each pile must be completed in one hour. Therefore, k must equal the largest pile size, 30.
Example 3:
Input: piles = [30,11,23,4,20], h = 6
Output: 23
Explanation:
For k = 23, the total is ceil(30/23)+ceil(11/23)+ceil(23/23)+ceil(4/23)+ceil(20/23) = 2+1+1+1+1 = 6 hours.
1 <= piles.length <= 10^4piles.length <= h <= 10^91 <= piles[i] <= 10^9piles = [3,6, 7, 11] h = 8
4
We have 4 banana piles: [3, 6, 7, 11] and Koko must finish within h = 8 hours.