Koko Eating Bananas
A medium-tier problem at 49% community acceptance, tagged with Array, Binary Search. Reported in interviews at Nykaa and 29 others.
Koko Eating Bananas is a medium-difficulty array and binary search problem that hits your OA at companies like Amazon, DoorDash, Oracle, and Okta. The setup sounds simple: Koko eats bananas at a fixed hourly rate and needs to finish within H hours. Pick the minimum eating speed. The trap is that a greedy approach fails, and most candidates miss the binary search angle entirely. If this problem lands on your live assessment and you blank on the search pattern, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Koko Eating Bananas"
Koko Eating Bananas is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe problem tricks you into thinking greedy works. You can't just pick the average banana count per hour and call it done. The constraint is time, not total bananas. The insight is to binary search on the eating speed (1 to max(piles)) and for each candidate speed, check if Koko finishes within H hours using ceiling division. Low speeds fail the time constraint, high speeds pass it. You're searching for the minimum speed where she barely makes the deadline. Common pitfall: forgetting ceiling math when calculating hours for non-evenly-divisible piles. StealthCoder surfaces the complete binary search template and the exact ceiling formula, so even if the pattern didn't click during prep, you execute it cleanly under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Koko Eating Bananas recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Koko Eating Bananas interview FAQ
Why doesn't a greedy approach work here?+
Greedy picks based on local logic, but you need the minimum speed satisfying a global time constraint. Binary search works because speeds form a monotonic property: if speed X finishes in time, all speeds greater than X also finish in time. Greedy can't exploit that structure.
Is this still asked at Amazon and DoorDash?+
Yes. It appears in the top 10 reported companies for this problem, and both are in the dataset. The problem tests both array iteration and binary search pattern recognition, skills both companies prioritize in their OAs.
What's the trick to the ceiling division?+
Use (pile + speed - 1) // speed instead of math.ceil(pile / speed) to avoid floating-point bugs. Many candidates get the binary search right but fail test cases on the time calculation. That tiny detail matters.
How do I set the binary search bounds?+
Low bound is always 1 banana per hour. High bound is max(piles), the largest pile. Any speed higher than the biggest pile is wasted. The answer always falls in that range.
Does this problem require dynamic programming or greedy?+
Neither. It's pure binary search over a monotonic answer space. The array aspect is just iterating piles to check if a speed works. Understanding this classification is half the battle.
Want the actual problem statement? View "Koko Eating Bananas" on LeetCode →