547. Koko Eating Bananas — Generalized K Piles

HardBinary SearchBinary Search on AnswerArray

Given k piles of bananas and H hours, each hour Koko picks one pile and eats up to her speed from it (finishing a smaller pile early). Return the minimum integer speed that lets her finish all piles within H hours. Input: '[piles], H'.

Input: '[piles], H'.

Output: Integer — the minimum speed.

Examples

Example 1
Input: [3,6,7,11], 8
Output: 4
Explanation: Speed 4 finishes within 8 hours.
Example 2
Input: [30,11,23,4,20], 5
Output: 30
Explanation: Tight time budget.
Example 3
Input: [1], 1
Output: 1
Explanation: Single pile.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →