Skip to main content

Koko Eating Bananas

Koko has n piles of bananas, piles[i] is the number of bananas in pile i Guards return in h hours, find minimum speed k to eat all bananas Each hour, Koko eats k bananas from one pile (or all if pile has < k) Example: piles = [3,6,7,11], h = 8 => 4 Example: piles = [30,11,23,4,20], h = 5 => 30

I binary search the eating speed, not the array. Every candidate speed is either fast enough or not, and that split is monotonic.

Examples

You write

min_eating_speed(piles: List[int], h: int)

  1. Example 1

    Input
    piles = [3,6,7,11], h = 8
    returns
    4
  2. Example 2

    Input
    piles = [30,11,23,4,20], h = 5
    returns
    30

The pattern behind it

Arrays & Hashing

I reach for it when

  • You catch yourself scanning the array again for every element.
  • The problem asks about duplicates, pairs, counts or groups.

Say this before you type. Say what the key is and what the value remembers, before you write the loop.

All 127 Arrays & Hashing problems

Binary Search

I reach for it when

  • The input is sorted, or sorted and then rotated.
  • You want a boundary: the first or last place something is true.

Say this before you type. Say the yes-or-no question, and which side each answer throws away.

All 19 Binary Search problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Find Minimum Eating Speedmedium
2Part 2
3Part 3

Each locked part opens in the editor once the part before it passes.

Prep guides that list this problem

Our company tags come from public interview write-ups. None of these is a confirmed question.