Trains the technique from
LeetCode 517Super Washing MachinesThis 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 mill has n grain bins standing in a row, and bins[i] is how many sacks bin i holds. Neighbouring bins are joined by a short conveyor; bin 0 and bin n - 1 each have a single neighbour, and the row does not wrap around.
The mill works in rounds. In one round you may choose any set of bins, and every chosen bin hands exactly one sack to one of its neighbours, either the one on its left or the one on its right. All the handovers of a round happen at the same time, so a bin may hand a sack away in the same round that it receives sacks, and a bin may receive from both sides at once. A bin can only hand over a sack it was already holding when the round began, and a bin holding no sacks cannot be chosen.
Return the least number of rounds after which every bin holds the same number of sacks, or -1 if no sequence of rounds can ever level the bins.
Example 1
The 16 sacks level out at 4 in every bin, and a run of 8 rounds gets them there.
Example 2
The 12 sacks level out at 4 in every bin, which is reached after 8 rounds.
Example 3
Eleven sacks cannot be shared evenly between three bins, so the bins can never end up level.
Example 4
The share is 4 each. In one round bin 0 hands a sack right and bin 2 hands a sack left at the same time, giving [5,2,5]; repeating that gives [4,4,4].
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 find_min_moves(bins: list[int]) -> int:public int findMinMoves(int[] bins)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.