Tap here to switch tabs
Problem
Submissions

Problem: Super Washing Machines

med
30 min
Try to solve the Super Washing Machines problem.

Statement

There are n washing machines arranged in a line. You are given an integer array machines where machines[i] denotes the number of dresses in the iextthi^{ ext{th}} washing machine.

In a single move, you can select any subset of machines and simultaneously transfer 11 dress from each selected machine to any one of its adjacent machines.

Return the minimum number of moves needed to equalize the number of dresses in all washing machines. If it is impossible to make every machine contain an equal number of dresses, return −1-1.

Constraints:

  • n == machines.length

  • 1≤1 \leq n ≤104\leq 10^4

  • 0≤0 \leq machines[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Super Washing Machines

med
30 min
Try to solve the Super Washing Machines problem.

Statement

There are n washing machines arranged in a line. You are given an integer array machines where machines[i] denotes the number of dresses in the iextthi^{ ext{th}} washing machine.

In a single move, you can select any subset of machines and simultaneously transfer 11 dress from each selected machine to any one of its adjacent machines.

Return the minimum number of moves needed to equalize the number of dresses in all washing machines. If it is impossible to make every machine contain an equal number of dresses, return −1-1.

Constraints:

  • n == machines.length

  • 1≤1 \leq n ≤104\leq 10^4

  • 0≤0 \leq machines[i] ≤105\leq 10^5