Sliding Window , Easy C++ ✅✅
Approach\n Describe your approach to solving the problem. \nUse Sliding Window to find out the maximum Sum of the Subarray With Unique Elements.\n# Complexity\n
# Approach\n<!-- Describe your approach to solving the problem. -->\nUse **Sliding Window** to find out the **maximum Sum** of the Subarray With **Unique Elements**.\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# Code\n```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& arr) {\n        int n  = arr.size();\n        unordered_map<int,int> freq;\n        int sum = 0,i = 0,ans = 0,j = 0;\n        while(j<n)\n        {\n            freq[arr[j]]++;\n            sum+=arr[j];\n            if(freq[arr[j]]>1)\n            {\n               while(i<j)\n               {\n                freq[arr[i]]--;\n                sum-=arr[i];\n                i++;\n                if(arr[i-1]==arr[j]) break;\n               }\n            }\n            ans = max(ans,sum);\n            j++;\n        }\n        return ans; \n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/d39bbc65-ab99-432d-a6d4-9d80ddec2a83_1688996697.8229485.jpeg)\n
['Sliding Window', 'C++']