Simple C++ Solution using hashset with comments
\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) {\n        // Creating hashset for quick access\n        unordered_set<int> set;\n
```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) {\n        // Creating hashset for quick access\n        unordered_set<int> set;\n        int n = nums.size();\n        int i = 0, j = 0, sum = 0, ans =0;\n        // Looping until we reach last elemenet\n        while (i < n and j < n){\n            // Check if we encountered unique element, if yes then increase sum and add to hashset\n            if (set.find(nums[j]) == set.end()){\n                set.insert(nums[j]);\n                sum += nums[j]; \n                ans = max(ans, sum);\n                j++;\n            }\n            // If we found a duplicate element then decrement the sum and remove element\n            else{\n                set.erase(nums[i]);\n                sum -= nums[i];\n                i++; \n            }\n        }\n        // Return max sum\n        return ans;\n    }\n};\n```\n\n**Please upvote the solution if this helps you understand better**\n\nThank you!
['Sliding Window']