Leetcode 517 Solution
This article provides solution to leetcode question 517 (super-washing-machines)
Access this page by simply typing in "lcs 517" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/super-washing-machines
Solution
class Solution:
def findMinMoves(self, machines: List[int]) -> int:
s = sum(machines)
if s % len(machines) != 0:
return -1
target = s // len(machines)
ans = 0
cnt = 0
for machine in machines:
cnt += machine - target
ans = max(ans, abs(cnt), machine - target)
return ans