Koko Eating Bananas
Binary search the eating speed: find the slowest speed that still finishes every pile in time.
The problem
Implement Solution.minEatingSpeed(piles, h). Koko eats bananas at a whole-number speed of k bananas per hour. Each hour she picks one pile and eats k bananas from it; if the pile has fewer than k left, she finishes it and waits for the rest of that hour. Return the smallest k that lets her finish every pile within h hours. For example, piles = [3, 6, 7, 11] and h = 8 returns 4. len(piles) <= h, 1 <= len(piles) <= 10000, 1 <= piles[i] <= 1000000000 and h <= 1000000000.
Starter code
class Solution:
def minEatingSpeed(self, piles, h):
passPublic examples
piles = [3, 6, 7, 11], h = 8gives4piles = [9], h = 2gives5piles = [2, 3], h = 5gives1
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
