Trains the technique from
LeetCode 2607Make K-Subarray Sums EqualThis 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 carousel carries n trays bolted in a ring and numbered 0 through n - 1, where n is the length of loads. Tray i holds loads[i] grams of grain, and tray n - 1 sits immediately before tray 0, so the numbering closes up into a circle.
A sweep is span trays taken one after another around the ring: it begins at some tray, steps to the next tray each time, and carries on past tray n - 1 onto tray 0 if it has not finished yet. There are n sweeps, one beginning at each tray.
The carousel is balanced when all n sweeps hold the same weight of grain. One adjustment either adds a gram to a single tray or takes a gram off a single tray. Return the fewest adjustments that leave the carousel balanced. A tray may be brought to any whole number of grams, including zero.
Example 1
Bringing the trays to 4, 3, 4, 3, 4, 3 grams takes 1 + 2 + 2 + 5 + 0 + 0 = 10 adjustments, and every sweep of four trays then holds 14 grams.
Example 2
Bringing the trays to 9, 4, 9, 4 grams takes 5 + 3 + 0 + 0 = 8 adjustments, and each of the four sweeps of two trays then holds 13 grams.
Example 3
Every sweep of two trays already holds 12 grams, so nothing has to be adjusted.
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_adjustments(loads: list[int], span: int) -> int:public long minAdjustments(int[] loads, int span)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.