FastPrepKoko Eating Bananas
Problems/Koko Eating Bananas

Koko Eating Bananas

Amazon logoAmazon● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon intern onsite interview. The sighting on 2026-07-21 was for an intern role. The report says this is Koko Eating Bananas or a problem much like it, but does not give the function signature, examples, or limits. Our version is about 90% the same as the reported question.

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) → int

Examples

Example 1

piles = [4,9,13]h = 8return = 4

At 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 = 8

Only 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 = 4

Speed 4 needs 1 + 2 + 3 + 4 = 10 hours. Speed 3 needs 1 + 3 + 4 + 5 = 13 hours.

Constraints

  • 1 <= piles.length <= 100000
  • 1 <= piles[i] <= 1000000000
  • piles.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

Interview reports that mention this question

  • Amazon SDE II Onsite and L5 Screens: 7 Experiences (Part 2 of 2)
  • Amazon SDE II OA and Interviews: 10 Experiences (Part 1 of 2)

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int minEatingSpeed(int[] piles, int h) {
        // write your code here
    }
}
Checking account…