Problem · Array
Koko Eating Bananas
Learn this problemProblem statement
You are given an array piles of positive banana counts and an integer h. Koko chooses one non-empty pile each hour and eats up to k bananas from it. If a pile contains fewer than k bananas, she empties that pile and does not begin another pile during the same hour.
Return the minimum positive integer speed k that lets Koko empty all piles within at most h hours.
Function
minEatingSpeed(piles: int[], h: int) → intExamples
Example 1
piles = [3,6,7,11]h = 8return = 4At speed 4, the piles take 1 + 2 + 2 + 3 = 8 hours. Speed 3 would require 10 hours.
Example 2
piles = [30,11,23,4,20]h = 5return = 30There are five piles and five hours, so each pile must be finished in one hour. The largest pile contains 30 bananas.
Constraints
1 <= piles.length <= 10^51 <= piles[i] <= 10^9piles.length <= h <= 10^9
More Tekion problems
- Maximum Sum of a Unique-Element SubarrayONSITE INTERVIEW · Seen Jul 2026
- Number of IslandsONSITE INTERVIEW · Seen Jul 2026
- Longest Balanced Substring After One SwapOA · Seen Jul 2026
- Minimum Size Subarray Sum With NegativesONSITE INTERVIEW · Seen Jul 2026
- Set Matrix ZeroesONSITE INTERVIEW · Seen Jul 2026