1695. Maximum Erasure Value

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1695

class Solution:
    def maximumUniqueSubarray(self, nums: List[int]) -> int:
        d = defaultdict(int)
        s = list(accumulate(nums, initial=0))
        res = j = 0
        for i, v in enumerate(nums, 1):
            j = max(j, d[v])
            res = max(res, s[i] - s[j])
            d[v] = i
        return res