517. Super Washing Machines
Read the full problem statement on LeetCode.
Difficulty: hard Acceptance: 42% Topics: Array, Greedy
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def findMinMoves(self, machines):
"""
:type machines: List[int]
:rtype: int
"""
total = sum(machines)
if total % len(machines): return -1
result, target, curr = 0, total / len(machines), 0
for n in machines:
curr += n - target
result = max(result, max(n - target, abs(curr)))
return result
Solution from kamyu104/LeetCode-Solutions · MIT