Minimum Dog Biscuit Eating Speed
Bruno is a dog that loves eating dog biscuits. There are several piles of biscuits, and biscuitPiles.get(i) is the number of biscuits in the ith pile. Bruno's owner will return after hours hours.
Bruno chooses a positive integer eating speed of speed biscuits per hour. During each hour, he selects one pile and eats up to speed biscuits from it. If the selected pile contains fewer than speed biscuits, he finishes that pile but does not start another pile during the same hour.
Find the minimum eating speed that allows Bruno to finish all the dog biscuits within the available number of hours.
Method Signature
int minimumBiscuitEatingSpeed(List<Integer> biscuitPiles, int hours)
Parameters
biscuitPiles contains the number of dog biscuits in each pile.
hours is the maximum number of hours Bruno has to finish all the biscuits.
Return Value
Return the minimum positive integer number of biscuits Bruno must eat per hour to finish every pile within hours hours.
Constraints
1 <= biscuitPiles.size() <= 10,000
biscuitPiles.size() <= hours <= 1,000,000,000
1 <= biscuitPiles.get(i) <= 1,000,000,000
0 <= i < biscuitPiles.size()
Examples
Example 1
minimumBiscuitEatingSpeed(biscuitPiles = List.of(4, 8, 12), hours = 6)
Output: 4
At a speed of 4 biscuits per hour, the piles require 1 + 2 + 3 = 6 hours. Any slower speed would require more than 6 hours.
Example 2
minimumBiscuitEatingSpeed(biscuitPiles = List.of(9, 15, 21), hours = 3)
Output: 21
Bruno has only one hour for each pile, so his eating speed must be large enough to finish the biggest pile in one hour.
Example 3
minimumBiscuitEatingSpeed(biscuitPiles = List.of(8, 13, 17), hours = 5)
Output: 9
At a speed of 9 biscuits per hour, the piles require 1 + 2 + 2 = 5 hours. A speed of 8 would require 6 hours.