517 Super Washing Machines
17 Super Washing Machines
You havensuper washing machines on a line. Initially, each washing machine has some dresses or is empty.
For eachmove, you could chooseany m(1 ≤ m ≤ n) washing machines, and passone dressof each washing machine to one of its adjacent washing machinesat the same time.
Given an integer array representing the number of dresses in each washing machine from left to right on the line, you should find theminimum number of movesto make all the washing machines have the same number of dresses. If it is not possible to do it, return -1.
Example1
Example2
Example3
Note:
The range of n is [1, 10000].
The range of dresses number in a super washing machine is [0, 1e5].
The Idea: (not currently working)
First check if it is possible to have an equivalent array. This is so, if the all the elements in the array can be equally divisible by the size of the array.
The sort the array, and exchange elements from the min and max until the numbers are equivalent. A quicker operation would be to take the difference between them, and accumulate this as the number of exchanges.
Last updated