 All Problems
Koko Eating Bananas
medium
binary search
amazon
facebook
google

Koko loves bananas. There are n piles of bananas and she has h hours. She can eat at most k bananas per hour. If a pile has fewer than k bananas, she finishes the pile and doesn't eat more that hour.

Return the minimum integer k such that she can eat all bananas within h hours.

Example 1:

Input piles: 3 6 7 11
h: 8
Output: 4

Example 2:

Input piles: 30 11 23 4 20
h: 5
Output: 30

Constraints:

  • 1 ≤ piles.length ≤ 10⁴
  • piles.length ≤ h ≤ 10⁹
  • 1 ≤ piles[i] ≤ 10⁹

Input format: First line: space-separated pile sizes. Second line: h.

Output format: Minimum eating speed k.

Run to check your code against the sample cases, or submit to run every case