Trains the technique from
LeetCode 3413Maximum Coins From K Consecutive BagsThis 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 picking aisle has bins at every whole position 1, 2, 3, ... running away from the door. The stock is recorded in stretches: runs[i] = [from, to, per] means every bin at a position from from to to inclusive holds exactly per items. No two stretches cover the same position, and a position no stretch mentions holds nothing.
A picker is sent down the aisle to clear span bins standing next to each other, that is span consecutive positions, all of them at position 1 or beyond. Return the largest number of items such a group of bins can hold.
Example 1
Clearing positions 6 through 9 picks up nothing at 6 and 7 and 10 items at each of 8 and 9, for 20 items.
Example 2
Clearing positions 10, 11 and 12 picks up 1 item at position 10 and 100 at each of 11 and 12, for 201 items.
Example 3
Only position 5 holds anything, so any group of three bins covering it, such as positions 4, 5 and 6, picks up 7 items.
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 richest_run(runs: list[list[int]], span: int) -> int:public long richestRun(int[][] runs, int span)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.