1
# Runtime: 170 ms (Top 20.15%) | Memory: 15 MB (Top 44.78%)
2
from itertools import accumulate
3

4

5
class Solution:
6
def findMinMoves(self, machines: List[int]) -> int:
7
n = len(machines)
8
summation = sum(machines)
9
if summation % n:
10
return -1
11
avg = summation // n
12
left = list(accumulate(machines))
13
result = 0
14
for i in range(n):
15
move_to_right = max(left[i] - (i + 1) * avg, 0)
16
move_to_left = max(
17
left[-1] - (left[i - 1] if i != 0 else 0) - (n - i) * avg, 0
18
)
19
result = max(result, move_to_right + move_to_left)
20
return result

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0