C++ | Two Pointer | Easy
The idea is to have two pointers/sliding window which tracks the sum of the elements inside the window.\nHere\'s how the sliding window works: \n1. To keep trac
The idea is to have two pointers/sliding window which tracks the sum of the elements inside the window.\nHere\'s how the sliding window works: \n1. To keep track of your unique numbers, initialize a map. \n2. If you see a new number, add it to your window and sum and map(pretty simple).\n3. If you see a repeated number however, keep moving the start pointer until you reach the repeated number. \n4. dont forget to keep updating your max sum :)\n\nThis way your sliding window will always have unique elements.\n\ncode:\n```class Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) {\n        int start = 0 , end = 0, n = nums.size(), ans = 0, sum = 0;\n        \n        map<int, int> mp;\n        \n        while(start < n && end < n){\n            \n            if(mp[nums[end]] == 0){\n                mp[nums[end]]  = 1;\n                sum += nums[end];\n                if(ans < sum){\n                    ans = sum;\n                }\n                end++;\n            }else{\n                sum -= nums[start];\n                mp[nums[start]] = 0;       \n                start++;\n            }\n            \n        }\n        \n        return ans;\n    }\n};\n```\nPlease upvote if you found it useful :)
['Two Pointers', 'C']