Koko loves to eat bananas. There are n piles of bananas, and the ith pile has piles[i] bananas. The guards have gone and will return after h hours. Koko can decide her eating speed of k bananas per hour. Each hour, she chooses one pile and eats k bananas from that pile. If the pile has fewer than k bananas, she eats all of them instead and does not eat any more bananas during that hour. Return the minimum integer k such that she can eat all the bananas within h hours.
Example 1
Input: piles = [3,6,7,11], h = 8
Output: 4
Explanation: If Koko eats 4 bananas per hour: 4 from pile 3 ? 1 hour 4 + 3 from pile 7 ? 2 hours 4 + 2 from pile 6 ? 2 hours 4 + 4 + 3 from pile 11 ? 3 hours Total time = 8 hours, so minimum speed is 4.
Example 2
Input: piles = [30,11,23,4,20], h = 5
Output: 30
Explanation: Koko must eat at speed 30 bananas per hour to finish all piles within 5 hours.
Example 3
Input: piles = [30,11,23,4,20], h = 6
Output: 23
Explanation: At speed 23 bananas per hour, Koko can finish all bananas in exactly 6 hours, which is the minimum possible speed.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
3 6 7 11 8
4
30 11 23 4 20 5
30