FastPrepKoko Eating Bananas
Problems/Koko Eating Bananas

Koko Eating Bananas

The D.E. Shaw Group logoThe D.E. Shaw Group● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: In a reply under a post about upcoming D. E. Shaw onsite rounds, someone described the screening round: a deep dive into a past project, then one binary search question they said was basically Koko Eating Bananas.

The reply does not say what, if anything, was different. Here you get the standard version: find the smallest whole-number eating speed that finishes all piles within h hours. Limits are added so that a fast search matters.

The judged task matches the report at about 80%.

Koko has n piles of bananas. Pile i holds piles[i] bananas. She has h hours to eat all of them.

Koko picks one whole-number eating speed k (bananas per hour) and keeps it the whole time. Each hour she chooses one pile and eats k bananas from it. If that pile has fewer than k bananas left, she eats all of them and does not start another pile during that hour.

Return the smallest speed k that lets her finish every pile within h hours.

Function

minEatingSpeed(piles: int[], h: int) → int

Examples

Example 1

piles = [4,9,7]h = 6return = 4

At speed 4, the piles take 1, 3, and 2 hours, which is 6 hours in total. At speed 3, they take 2, 3, and 3 hours, which is 8 hours, too many.

Example 2

piles = [12,5,20,8]h = 4return = 20

There are 4 piles and 4 hours, so each pile must be finished in one hour. The biggest pile has 20 bananas, so the speed must be 20.

Example 3

piles = [7]h = 3return = 3

At speed 3, Koko eats 3, 3, and then the last 1: 3 hours. At speed 2, she needs 4 hours (2, 2, 2, 1).

Constraints

  • 1 <= piles.length <= 10^4
  • piles.length <= h <= 10^9
  • 1 <= piles[i] <= 10^9

More The D.E. Shaw Group problems

  • Sum of Smallest Non-DivisorsPHONE SCREEN · Seen Nov 2026
  • Count Lucky TicketsOA · Seen Nov 2026
  • Count Palindrome Addition ChoicesOA · Seen Nov 2026
All The D.E. Shaw Group interview questionsSee The D.E. Shaw Group hiring insights
Saved
class Solution {
    public int minEatingSpeed(int[] piles, int h) {
        // Write your code here.
    }
}
Checking account…