simple and easy C++ solution 😍❤️‍🔥
\n\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\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```cpp []\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) \n    {\n        // Declare a map to keep track of the frequency of each number in the current subarray.\n        unordered_map<int, int> mp;\n        \n        // Initialize variables to store the maximum sum of unique subarray, current sum, and two pointers.\n        int maxValue = 0; // Maximum sum of unique subarray found so far.\n        int sum = 0;      // Current sum of the subarray.\n        int i = 0;        // Left pointer for the sliding window.\n        int j = 0;        // Right pointer for the sliding window.\n        int n = nums.size(); // Size of the input array.\n\n        // Iterate with the right pointer j through the entire array.\n        while(j < n)\n        {\n            // Add the current number to the sum and increment its frequency in the map.\n            sum += nums[j];\n            mp[nums[j]]++;\n\n            // If the frequency of the current number exceeds 1, we have duplicates.\n            // We need to adjust the left pointer i to make the subarray unique.\n            while(mp[nums[j]] > 1)\n            {\n                // Decrease the frequency of the number at the left pointer i and subtract its value from the sum.\n                mp[nums[i]]--;\n                sum -= nums[i++]; // Move the left pointer to the right.\n            }\n\n            // Update maxValue if the current sum is greater than the previously recorded maximum sum.\n            maxValue = max(sum, maxValue);\n            \n            // Move the right pointer to the next position.\n            j++;\n        }\n\n        // Return the maximum sum of the unique subarray found.\n        return maxValue;\n    }\n};\n```\n\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n
['Array', 'Hash Table', 'Sliding Window', 'C++']