Koko Eating Bananas

Medium · Binary Search · Array · Binary Search

Problem

piles[i] bananas sit in pile i, and there are h hours available. At a chosen speed of k bananas per hour, each hour is spent on a single pile: if fewer than k remain there, the rest of the hour is wasted.

Return the smallest integer k that finishes every pile within h hours.

Examples

Input: piles = [3,6,7,11], h = 8
Output: 4

Speed 4 takes 1+2+2+3 = 8 hours; speed 3 would take 10.

Input: piles = [30,11,23,4,20], h = 5
Output: 30

One pile per hour, so the speed must match the largest.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…