Leetcode 517 Solution

This article provides solution to leetcode question 517 (super-washing-machines)

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