Koko Eating Bananas
Real-world version: Overnight Print RateThe statement here is our own: the same inputs, outputs and technique.
A copy shop leaves one press running through the night. stacks[i] is the number of sheets waiting in stack i, and the shift lasts hours hours.
The operator sets a single whole number rate before leaving, and it cannot be touched again. Once an hour begins, the press draws from exactly one stack and pulls at most rate sheets out of it. A stack holding fewer than rate sheets is simply emptied, and the press then sits idle until the hour is up instead of turning to another stack.
The operator would rather run the press gently, so return the smallest rate that still leaves every stack empty by the end of the shift.
The shift is never shorter than the number of stacks, so a workable rate always exists.
Examples
Example 1
- Input
- stacks = [15, 8, 5, 20], hours = 9
- Output
- 7
At 7 sheets an hour the stacks take 3, 2, 1 and 3 hours, which is 9 in total. Dialling 6 pushes the first and last stacks to 3 and 4 hours, for 10 in total, one hour past the shift.
Example 2
- Input
- stacks = [20, 14, 9], hours = 3
- Output
- 20
The shift allows exactly one hour per stack, so the press has to clear the biggest stack in a single hour and the rate cannot dip below 20.
Example 3
- Input
- stacks = [17], hours = 17
- Output
- 1
A single stack of 17 sheets fits in 17 one-sheet hours, and no smaller whole rate exists.
Constraints
- 1 <= stacks.length <= 10^4
- stacks.length <= hours <= 10^9
- 1 <= stacks[i] <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def min_print_rate(stacks: list[int], hours: int) -> int:public int minPrintRate(int[] stacks, int hours)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's