Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Balance Circular Array

Try to solve the Minimum Moves to Balance Circular Array problem.

Statement

You are given a circular integer array balance of size n.

In one move, you can transfer 11 unit from an index i with balance[i] >0> 0 to an adjacent index (either (i + 1) % n or (i - 1 + n) % n).

Return the minimum number of moves required to make every element in balance greater than or equal to 00, or −1-1 if it is impossible.

Constraints:

  • 1≤n==1 \leq n == balance.length ≤105\leq 10^5

  • −109≤-10^9 \leq balance[i] ≤109\leq 10^9

  • There is at most 11 negative value in balance initially.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Balance Circular Array

Try to solve the Minimum Moves to Balance Circular Array problem.

Statement

You are given a circular integer array balance of size n.

In one move, you can transfer 11 unit from an index i with balance[i] >0> 0 to an adjacent index (either (i + 1) % n or (i - 1 + n) % n).

Return the minimum number of moves required to make every element in balance greater than or equal to 00, or −1-1 if it is impossible.

Constraints:

  • 1≤n==1 \leq n == balance.length ≤105\leq 10^5

  • −109≤-10^9 \leq balance[i] ≤109\leq 10^9

  • There is at most 11 negative value in balance initially.