Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Koko Eating Bananas

Medium
binary-searcharray

Koko has piles of bananas and h hours. Each hour she picks one pile and eats up to k bananas from it (a pile smaller than k still costs the whole hour). Return the minimum integer speed k that finishes all piles within h hours.

Input

  • Line 1: space-separated integers piles
  • Line 2: integer h

Output: the minimum k.

Example 1
Input:
3 6 7 11
8
Output:
4
Example 2
Input:
30 11 23 4 20
5
Output:
30
Example 3
Input:
30 11 23 4 20
6
Output:
23

Constraints

  • 1 ≤ piles.length ≤ 10^4
  • piles.length ≤ h ≤ 10^9
  • 1 ≤ piles[i] ≤ 10^9
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.