✅C++ | ✅Use Sliding window and hashing | ✅Simple and efficient solution | 🗓️ DLC June, Day 12
Please upvote if it helps \u2764\uFE0F\uD83D\uDE0A\nTC: O(N), SC: O(2N) ~ O(N)\n\nCode:\n\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>&
**Please upvote if it helps \u2764\uFE0F\uD83D\uDE0A**\n**TC: O(N), SC: O(2N) ~ O(N)**\n\n**Code:**\n```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) \n    {\n        int l=0, r=0; //define left and right pointers for sliding windows approach\n        \n        vector<int> sum_arr; //sum_arr stores sum of element of nums at index i;\n        sum_arr.push_back(0); //initially l and r at 0 so to consider element at index 0 we need to take 0 at index 0\n        \n        int sum=0, score=nums[0];\n        for(auto it:nums) //storing sum into sum_arr\n        {\n            sum += it;\n            sum_arr.push_back(sum);\n        }\n        \n        unordered_map<int, int> mp; //stores element and their index\n        \n        while(r<nums.size()) //iterate till r pointer is lesser than nums\' size \n        {\n            if(mp.find(nums[r]) != mp.end()) l=max(l, mp[nums[r]]+1); //when repeated element come we move left pointer of the right of repeated element\n            mp[nums[r]] = r; //assigning index to the element\n            score = max(score, sum_arr[r+1]-sum_arr[l]); //get max score\n            r++; //move r by 1 \n        }\n        return score;\n        \n    }\n};\n```
['C', 'Sliding Window', 'C++']