← Practice · Binary search

Koko Eating Bananas Medium

Koko has piles of bananas, piles[i] in pile i, and h hours. Each hour she picks one pile and eats up to k bananas from it (finishing a smaller pile wastes the rest of that hour). Return the minimum integer speed k that lets her finish all piles within h hours. It is guaranteed that h >= piles.length.

Examples

  • piles = [3,6,7,11], h = 8 -> 4
  • piles = [30,11,23,4,20], h = 5 -> 30

Define a function named minEatingSpeed in JavaScript.

00:00▶ Visualize

JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests