Koko Eating Bananas
Updated
Problem 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 interview questions
- Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
- Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
- Maximum Sum of a Unique-Element SubarrayONSITE INTERVIEW · Seen Jul 2026
- Number of IslandsONSITE INTERVIEW · Seen Jul 2026
- Minimum Size Subarray Sum With NegativesONSITE INTERVIEW · Seen Jul 2026
- Set Matrix ZeroesONSITE INTERVIEW · Seen Jul 2026
- Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
- Dungeon GamePHONE SCREEN · Seen Sep 2026
- IPOPHONE SCREEN · Seen Sep 2026
- Coin Game From The EndsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Koko Eating BananasAmazon · ONSITE INTERVIEW
- Multinomial Sampling with Distribution ChecksNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Maximum Alloy Production Within BudgetMicrosoft · OAMicrosoft interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum of a Convex FunctionRippling · PHONE SCREENRippling interview questions
- TikTok Video Relevance AdjustmentTikTok · OATikTok interview questions
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Percentile and Boundary QueriesDatadog · PHONE SCREENDatadog interview questions