Skip to content
LC-1749 Medium LeetCode

1749. Maximum Absolute Sum of Any Subarray

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 72% Topics: Array, Dynamic Programming
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def maxAbsoluteSum(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        curr = mx = mn = 0
        for num in nums:
            curr += num
            mx = max(mx, curr)
            mn = min(mn, curr)
        return mx-mn

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions