Koko Eating Bananas
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Koko has n piles of bananas, where the i-th pile holds piles[i] bananas. She has a fixed window of h hours before the warehouse guards return.
Koko picks a single, constant eating rate k (bananas per hour) and keeps it for the whole window. Each hour she chooses one pile and eats up to k bananas from it:
- If the chosen pile has at least k bananas left, she eats exactly k and moves on next hour.
- If the pile has fewer than k bananas left, she eats the rest of that pile and does nothing else for the remainder of that hour (she will not start a second pile within the same hour).
Koko wants to eat as slowly as possible while still finishing every pile within h hours. Return the **minimum** integer rate k such that she can eat all the bananas in h hours or less.
It is guaranteed that h >= n, so a valid rate always exists.
Examples
Constraints
- `1 <= piles.length <= 10^4`
- `piles.length <= h <= 10^9`
- `1 <= piles[i] <= 10^9`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.