PrefixSum Array + Sliding Window || Easy Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nPrefixSum Array  +  Sliding Window \n\n# Approach\n Describe your approach to solving t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nPrefixSum Array  +  Sliding Window \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can use the concept of prefix sum array to currect our current window sum in case of repeating element.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution:\n    def maximumUniqueSubarray(self, nums: List[int]) -> int: \n        \n        # ans --> final answer\n        # cur --> current window sum\n        # start --> current window starting position\n        \n        ans = cur = start = 0   \n        d = {}          # stores previous(latest) position of element\n\n        for i,j in enumerate(nums):\n            if i > 0: nums[i] += nums[i-1]      # making prefixSum array \n            cur += j                \n            if j in d and d[j] >= start:  # if element is present already in our current window \n                ind = d[j] \n                cur = cur - (nums[ind] - nums[start-1] if start != 0 else nums[ind])  # correction in current window sum\n                start = ind + 1     # current window starting position gets changed\n\n            d[j] = i  \n            ans = max(ans,cur)\n\n        return ans\n```
['Python3']