Koko Eating Bananas
Updated
Problem statement
You are given an array piles of positive banana counts and an integer h. Koko chooses one nonempty pile each hour and eats up to k bananas from that pile, where k is a positive integer speed. If the pile contains fewer than k bananas, she empties it and does not start another pile during that hour.
Return the minimum integer speed k that lets Koko empty every pile within at most h hours.
Function
minEatingSpeed(piles: int[], h: int) → intExamples
Example 1
piles = [4,9,13]h = 8return = 4At speed 4, the piles take 1 + 3 + 4 = 8 hours. Speed 3 needs 2 + 3 + 5 = 10 hours, so 4 is minimal.
Example 2
piles = [8,8,8]h = 3return = 8Only one pile can be chosen per hour. With exactly three hours for three piles, each pile must be emptied in one hour, requiring speed 8.
Example 3
piles = [1,7,10,15]h = 10return = 4Speed 4 needs 1 + 2 + 3 + 4 = 10 hours. Speed 3 needs 1 + 3 + 4 + 5 = 13 hours.
Constraints
1 <= piles.length <= 1000001 <= piles[i] <= 1000000000piles.length <= h <= 1000000000
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
- 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