The Koko Eating Bananas interview question is a resource-optimization problem. Koko loves bananas. There are several piles of bananas, and Koko has hours to eat all of them. Each hour, she chooses a pile and eats bananas from it. If the pile has fewer than , she finishes the pile and stops for that hour. Your task is to find the minimum integer speed such that she can finish all piles within hours.
This is a high-frequency question at companies like Uber, Amazon, and Netflix. It tests your ability to apply Binary Search on the answer space. It evaluations whether you can recognize a monotonic relationship: as the eating speed increases, the total hours required decreases. This is a core Binary Search interview pattern.
This problem follows the Binary Search on Value pattern.
canFinish(speed) function that calculates the total hours needed: sum(ceil(pile / speed)).canFinish(mid) <= H, then mid is a valid speed. Try smaller: ans = mid, right = mid - 1.canFinish(mid) > H, the speed is too slow. Try larger: left = mid + 1.Piles: [3, 6, 7, 11], .
round() or standard division instead of ceil(). The integer trick for ceil(a/b) is (a + b - 1) / b."Minimize the maximum" or "Find the minimum rate to satisfy a condition" are the "Bat-Signals" for Binary Search on the answer. Master this pattern as it appears in dozens of hard array problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find First and Last Position of Element in Sorted Array | Medium | Solve | |
| Find Peak Element | Medium | Solve | |
| Find Minimum in Rotated Sorted Array | Medium | Solve | |
| Search in Rotated Sorted Array | Medium | Solve | |
| Capacity To Ship Packages Within D Days | Medium | Solve |