Problem 4004 · Hard

Minimum Moves to Balance Circular Array II

People stand in a circle with integer balances, and one move hands exactly 1 unit to an adjacent person. Find the fewest moves that leave nobody negative, or -1 when that cannot happen.

Open the interactive visualisation