Problem
Koko has some piles of bananas. The pile at index i has piles[i] bananas. Koko must eat all the bananas in h hours or fewer.
Koko chooses one eating speed k, in bananas for each hour. Each hour, Koko chooses one pile and eats k bananas from it. If the pile has fewer than k bananas, Koko eats all of them and eats no more during that hour.
Return the smallest integer k that lets Koko eat all the bananas in h hours or fewer.
Example 1
- Input:
- piles = [4,9,6], h = 5
- Output:
- 5
- Explanation:
- At the speed 5, the three piles take 1, 2 and 2 hours, so Koko needs 5 hours. At the speed 4, Koko needs 6 hours.
Example 2
- Input:
- piles = [10,2,7,15], h = 4
- Output:
- 15
- Explanation:
- Koko has 4 hours for 4 piles, so each pile must take one hour. The largest pile has 15 bananas.
Example 3
- Input:
- piles = [12,5,9], h = 10
- Output:
- 3
Constraints
- 1 <= piles.length <= 10^4
- piles.length <= h <= 10^9
- 1 <= piles[i] <= 10^9
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- 132 Pattern
Coding · Array · Binary Search · Monotonic Stack
- Avoid Flood in The City
Coding · Array · Binary Search · Greedy
- Binary Search
Coding · Array · Binary Search
- Binary Searchable Numbers in an Unsorted Array
Coding · Array · Binary Search · Monotonic Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 5 records
Coupang
Leetcode 875. Koko Eating Bananas
Reported Oct 14, 2026 · 1 source report
STAFF
Source snapshot: Nov 12, 2026
View sourceDoorDash
Leetcode 875. Koko Eating Bananas
Reported Dec 17, 2025 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceGoldman Sachs
Leetcode 875. Koko Eating Bananas
Reported Apr 6, 2026 · 2 source reports
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 875. Koko Eating Bananas
Reported May 24, 2026 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026