Trains the technique from
LeetCode 875Koko Eating BananasThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
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
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
A single stack of 17 sheets fits in 17 one-sheet hours, and no smaller whole rate exists.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def min_print_rate(stacks: list[int], hours: int) -> int:public int minPrintRate(int[] stacks, int hours)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.