Koko Eating Bananas
Reported by candidates from Tekion's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Tekion OA reported in July 2025 is Koko Eating Bananas, and the trap is that a greedy or linear scan on speed dies the moment piles hit 10^9. If you've got an invite in your inbox, expect binary search on the answer, not on the array. The sample cases look friendly. The constraints aren't. Piles up to 10^9 and 10^5 of them means you need log of the max pile times n, nothing slower. This page gives you the pattern, the one pitfall that fails hidden tests, and a hedge. StealthCoder is that hedge, sitting invisibly on screen if you blank mid-assessment.
The problem
You are given an array piles of positive banana counts and an integer h. Koko chooses one non-empty pile each hour and eats up to k bananas from it. If a pile contains fewer than k bananas, she empties that pile and does not begin another pile during the same hour. Return the minimum positive integer speed k that lets Koko empty all piles within at most h hours. Function minEatingSpeed(piles: int[], h: int) → int Examples Example 1 piles = [3,6,7,11] h = 8 return = 4 At speed 4, the piles take 1 + 2 + 2 + 3 = 8 hours. Speed 3 would require 10 hours. Example 2 piles = [30,11,23,4,20] h = 5 return = 30 There are five piles and five hours, so each pile must be finished in one hour. The largest pile contains 30 bananas. Constraints 1 <= piles.length <= 10^5 1 <= piles[i] <= 10^9 piles.length <= h <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: speed k has a monotonic feasibility. If k works, every larger k works too. So binary search k between 1 and max(piles). For each candidate, compute hours as the sum of ceil(pile / k) across piles, and check it's at most h. If it fits, move high down to mid. If not, move low up past mid. Return low. The pitfall is the ceiling division. Write it as (pile + k - 1) // k, or you'll get off-by-one failures on piles that divide evenly. Another trap is setting the low bound to 0, which causes divide by zero. Start at 1. In Java or C++, the hour total can overflow 32 bits, since 10^5 piles of 10^9 with k=1 is huge, so use a long. If you freeze on any of this during the live OA, StealthCoder can show you the full solution from the screen without the proctor seeing it.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Koko Eating Bananas cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as koko eating bananas. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Tekion's OA.
Tekion reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Koko Eating Bananas FAQ
What's the trick in Koko Eating Bananas?+
Binary search on the answer, not the array. Speed has a monotonic property: if speed k finishes in time, any faster speed does too. Search k from 1 to the largest pile, and test each candidate by summing ceil(pile / k) and comparing to h.
What edge case breaks a naive solution?+
Two things. Trying every speed from 1 upward times out when piles reach 10^9. And floor division instead of ceiling undercounts hours for piles that don't divide evenly. Use (pile + k - 1) / k and keep the hour total in a 64-bit integer.
What's the time complexity I should state?+
O(n log m), where n is the number of piles and m is the largest pile. The binary search runs about 30 iterations for 10^9, and each iteration scans all piles once. Space is O(1). That comfortably fits 10^5 piles.
Why is the upper bound the max pile?+
Since Koko can only work one pile per hour, speeds above the largest pile give no benefit. Every pile already takes one hour. And h is at least the number of piles, so max(piles) is always a valid speed. That guarantees your search has an answer.
How do I prepare for this in 48 hours?+
Write the binary search template from memory twice. Use the lower-bound form: while low < high, mid = (low + high) / 2, if feasible then high = mid, else low = mid + 1. Then test both examples by hand. Also practice similar problems where you search over the answer, like capacity or split-array style questions.