Maximum Erasure Value - ✅C++ |  Python | O(N) | Easy Solution
Maximum Erasure Value\nThis problem is very much similar to Longest Substring Without Repeating Characters. \nI recommend to solve this problem before trying Ma
# Maximum Erasure Value\nThis problem is very much similar to Longest Substring Without Repeating Characters. \nI recommend to solve this problem before trying Maximum Erasure Value - https://leetcode.com/problems/longest-substring-without-repeating-characters \n\n**Example:**\n**nums = [4,2,4,5,6]**\nThe output should be maximum subarray with unique elements present in it.\n\n*  We take additional space as hashset and use the concept of sliding window.\n*  For the sliding window technique, we take two pointers as l(left) and r(right).\n*  We use cur to track the current sum in the current window.\n*  When there is an duplicate, we move the l untill the current window has no duplicate and at the same time we remove the nums[l] in the hashset.\n*  We keep updating the result by taking maximum of result and current sum.\n\nFor the above example,\n1.  set={4}         maximum =4\n2.  set={4,2}      maximum= 6\n3.  set= {2,4}     maximum=6\n4.  set={2,4,5}   maximum=11\n5.  set={2,4,5,6} maximum=17\n\n***So, the output is 17***\n \n**C++ Code**\n```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) {\n        unordered_set<int> s;\n        int cur = 0, res = 0, l = 0;\n        for (int r=0;r<nums.size();r++) {\n            while (s.find(nums[r]) != s.end()) {\n                cur=cur-nums[l];\n                s.erase(nums[l]);\n                l=l+1;\n            }\n            cur=cur+nums[r];\n            s.insert(nums[r]);\n            res = max(res, cur);\n        }\n        return res; \n    }\n};\n```\n\n**Python Code**\n```\nclass Solution:\n    def maximumUniqueSubarray(self, nums: List[int]) -> int:\n        res=0\n        cur=0\n        s=set()\n        l=0\n        for r in range(len(nums)):\n            while nums[r] in s:\n                s.remove(nums[l])\n                cur=cur-nums[l]\n                l=l+1\n            s.add(nums[r])\n            cur=cur+nums[r]\n            res=max(res,cur)\n        return res\n```\n\n**Time Complexity - O(N)**\n**Space Complexity - O(N)**\n\n\n\n\n\n
['C', 'Sliding Window', 'Python', 'C++']