✅C++ || Using Prefix Sum & MAP || 🗓️ Daily LeetCoding Challenge June, Day 12
Please Upvote If It Helps\n\n\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) \n    {\n        //finding subarray(with unique eleme
**Please Upvote If It Helps**\n\n```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& nums) \n    {\n        //finding subarray(with unique elements) with maximum score\n        int score = -1;\n        \n        //storing index of the elements\n        vector<int> map(1e4+1, -1); \n        \n        \n        //make prefix sum to get score\n        vector<int> prefixSum;\n        int sum = 0;\n        for(int it: nums)\n        {\n            sum+= it;\n            prefixSum.push_back(sum);\n        }\n        \n        //finding subarray(with unique elements) with maximum score\n        int start = 0;\n        for(int i=0; i<nums.size(); i++)\n        {\n            if(map[nums[i]] != -1)\n            { \n                //if element repeats in nums, update start\n                start = max(start, map[nums[i]]+1);\n            }\n            \n            map[nums[i]] = i;   //update index in map\n            \n            //get max score\n            int left = (start==0)? 0: prefixSum[start-1];\n            \n            score = max(score, prefixSum[i]- left);  \n        }\n        \n        return score;\n    }\n};\n```
[]