Back to Practice
#0261

Koko Eating Bananas

MediumDSA28 min20 XP

Problem

Koko eats k bananas per hour from one pile at a time. Return the minimum integer k so all piles are eaten within h hours.

Why This Matters

This is the canonical binary-search-on-answer problem: the answer is not an index, but feasibility is monotonic.

Function Signature

def min_eating_speed(piles, h):

Examples

Example 1
Inputpiles = [3,6,7,11], h = 8
Output4

Speed 4 finishes in 8 hours; speed 3 is too slow.

Constraints

  • Return the exact requested value.
  • Handle edge cases cleanly.
  • Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Classic speed
Input[3,6,7,11], h = 8
Expected4

4 is the smallest feasible speed.

Large pile
Input[30,11,23,4,20], h = 5
Expected30

Only speed 30 can finish one pile per hour.

Hidden Test Categories
h much larger than piles countsingle pileanswer near lower bound