← DiffPush

Koko eating banana

Baseline Binary Search · In Search Space O(n log M), where M is the largest pile · O(1)

Pacing a Robotic Picker Before the Shift Ends

A warehouse robot must clear several part bins before the maintenance crew returns in h minutes. Each minute it works on one bin at a fixed pick rate; a smaller bin finishes early and the robot idles for the rest of that minute. Choose the slowest rate that still empties every bin in time.

Input: An array piles of n positive integers and an integer h, the deadline in hours.

Output: The minimum integer eating speed k such that all piles are finished within h hours.

Constraints

Examples

Example 1

Input: {"piles":[3,6,7,11],"h":8}
Output: 4
At rate 4 the bins take 1, 2, 2 and 3 minutes for a total of 8; rate 3 would need 9.

Example 2

Input: {"piles":[30,11,23,4,20],"h":5}
Output: 30
With only five minutes and five bins, one bin must go per minute, so the rate must cover the largest bin.

Solve this in your browser →

Also on LeetCode ↗