Koko Eating Bananas
Write the code, see it run, pass the checks.
The problem
- medium
- Code
- Pro
Koko has piles of bananas and a number of hours to eat them all. She picks a speed k, a whole number of bananas per hour. Each hour she eats k bananas from one pile, or what's left of it if that's fewer, and doesn't start another pile in that hour. Write minEatingSpeed(piles, hours): return the smallest k that lets her finish in time. Each pile holds 1 to 1,000,000,000 bananas, and hours is at least the number of piles. For example, minEatingSpeed([3, 6, 7, 11], 8) is 4. The checks include 100,000 piles, so trying every speed from 1 upward is too slow.
Your code must pass
- Finds the slowest speed that finishes in time
- Eats a whole pile an hour when hours equals the number of piles
- Returns 1 when there's time for one banana an hour
- Is fast enough for 100,000 piles