482. Koko Eating Bananas

MediumBinary SearchBinary Search on AnswerArray

Koko has piles of bananas and H hours before the guards return. Each hour she chooses a pile and eats up to k bananas from it (if the pile has fewer, she eats the whole pile and stops for that hour). Return the minimum integer eating speed k so she finishes all piles within H hours. Input: '[piles], H'.

Input: '[piles], H'.

Output: Integer — the minimum eating speed.

Examples

Example 1
Input: [3,6,7,11], 8
Output: 4
Explanation: Speed 4 finishes in 8 hours.
Example 2
Input: [30,11,23,4,20], 5
Output: 30
Explanation: Tight time budget.
Example 3
Input: [30,11,23,4,20], 6
Output: 23
Explanation: More time allows slower speed.

Constraints

Asked by

AmazonAccentureSwiggyAdobeMicrosoftBloomberg
Solve this problem in the editor →