✔ C++ ‖ Sliding Window Solution
Intuition:-\n->We have to find distinct subarray with largest sum\n-> Since we have to find largest sum distinct subarray, I have used unordered map to get uniq
**Intuition:-**\n**->We have to find distinct subarray with largest sum**\n**->** Since we have to find largest sum distinct subarray, I have used unordered map to get unique elements.\n**->** Initially map will be empty and whenever we are traversing we go on adding elements.\n**->** Whenever we find by adding next value subarray will not be distinct,we go on removing the elements from beginning of our subarray.\n**->** We use currsum and maxsum variables to store current window sum and overall max sum.\n**->** For each element\'s insertion we will be calculating maxsum and currsum.\n\n**Complexity:-**\n**Time=O(N)** due to one traversal\n**Space=O(N)** due to additional map.\n\nHoping you understood the solution :)\nPlease upvote if you found it usefull !\nThank you..\n```\nclass Solution {\npublic:\n    int maximumUniqueSubarray(vector<int>& a) {\n\t\tint n=a.size();\n        unordered_map<int,int> mp;\n        int mxScore=0,currScore=0;\n        int j=0;\n        for(int i=0;i<n;i++){\n            mp[a[i]]++;\n            while(mp[a[i]]>1){\n                mp[a[j]]--;\n                currScore-=a[j];\n                j++;\n            }\n            currScore+=a[i];\n            mxScore=max(mxScore,currScore);\n        }\n        return mxScore;\n    }\n};\n```
['C', 'Sliding Window', 'C++']