522. Minimum Eating Speed for All Piles

MediumBinary SearchBinary Search on AnswerArray

Given piles of items and H hours, each hour you pick one pile and consume up to speed items from it (if fewer remain you finish that pile and stop for the hour). Return the minimum integer speed that lets you finish every pile 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 hour budget.
Example 3
Input: [30,11,23,4,20], 6
Output: 23
Explanation: Looser budget allows a slower speed.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →