C++ Sliding window + hashmap 🥓🥓
Keep a frequency map of the numbers in the window.\n\nwhile the count of the latest number in the window is greater than 1, shrink the window.\n\nrecord the bes
Keep a frequency map of the numbers in the window.\n\nwhile the count of the latest number in the window is greater than 1, shrink the window.\n\nrecord the best answer.\n\n**Solved LIVE ON TWITCH.  Link in profile.  I stream Everyday at 6pm PT**  \n\n```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) {\n        int n = nums.size();\n        int L = 0;\n        int R = 0;\n        \n        unordered_map<int, int> freqMap;\n        int sum = 0;\n        int ans = 0;\n        while(R < n) {\n            int right = nums[R++];\n            sum += right;\n            freqMap[right]++;\n            \n            while(freqMap[right] > 1) {\n                int left = nums[L++];\n                freqMap[left]--;\n                sum -= left;\n            }\n            ans = max(ans, sum);\n        }\n        return ans;\n    }\n};\n```
[]