Loading practice problems…
Loading your practice workspace…
Loading code editor…
16 / 29
Sign in
Algorithms/Binary Search on Answer

Koko Eating Bananas

medium35 min

Koko has several piles of bananas and h hours. At an integer speed k, she spends one hour consuming up to k bananas from one pile.

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

Example 1

Inputpiles = [3, 6, 7, 11], h = 8

Output4

Example 2

Inputpiles = [30, 11, 23, 4, 20], h = 5

Output30

Constraints

  • 1 ≤ piles.length ≤ h ≤ 100,000
  • 1 ≤ piles[i] ≤ 1,000,000,000
Binary Search on AnswerArrays