Koko Eating Bananas
MediumAsked in:Amazon•Stage:Onsite
arraybinary_searchmath
Problem Statement
Koko has a list of piles of bananas, where piles[i] denotes the number of bananas in the i-th pile. Each hour she chooses a pile and eats up to K bananas from it; if the pile has fewer than K bananas, she eats the whole pile. Koko wants to finish all piles within H hours. Determine the minimum integer K that allows her to do so.
Input Format
Two inputs are provided: an integer array piles representing the number of bananas in each pile, and an integer H representing the total hours Koko has to finish eating all bananas.
Output Format
Return the smallest integer K such that Koko can eat all the bananas within H hours.
Constraints
- 1 <= n <= 10^5
- 1 <= piles[i] <= 10^9
- 1 <= H <= 10^9