Loading...
You are given an integer array batches of length n, where batches[i] is the size of the i-th batch, and an integer hours.
You must choose a single integer processing rate k before work begins. Each hour, exactly one batch is processed: up to k units are removed from that batch. If fewer than k units remain in the batch, all of them are processed and the rest of that hour is wasted; a second batch is never started within the same hour.
A smaller rate is preferred, but every batch must be fully processed within hours hours. Processing a batch of size b at rate k therefore takes ceil(b / k) hours.
Return the minimum integer rate k such that all batches can be processed within hours hours.
Input: batches = [3,6,7,11], hours = 8
Output: 4
Explanation: At rate 4, the batches take 1 + 2 + 2 + 3 = 8 hours, exactly the 8 hours available.
Input: batches = [30,11,23,4,20], hours = 5
Output: 30
Explanation: Five batches and only five hours: each batch must be cleared in a single hour, so the rate must cover the largest batch.
Input: batches = [30,11,23,4,20], hours = 6
Output: 23
Explanation: One extra hour lets the batch of 30 be split across two hours, so a rate of 23 is enough.
batches.length ≤104batches.length ≤hours≤109batches[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.