#3776

Minimum Moves to Balance Circular Array

expert · 1015 · lc medium +32 · 40.2% accepted · 111 likes · top 20%

Description

Given a circular array balance of length n representing each person's net balance, where in a single move exactly 1 unit may be transferred to an immediate neighbor, return the minimum number of moves needed to make every person's balance non-negative, or -1 if impossible (at most one index starts with a negative balance).

Code

1
2
3