C++ | Track max with particular sum
Explanantion:-\n1. We  have to track maximum number with particular sum;\n2.  For those who find it difficult to understand.\nlets say you are at ith index so y
**Explanantion:-**\n1. We  have to track maximum number with particular sum;\n2.  For those who find it difficult to understand.\n**lets say you are at ```ith``` index so you calculate sum of digits of that number(call it as digitSum). So now what you want is other number whose sum of digits =digitSum and index less then ```i```\nHow can you check if there exist number whose sum of digits =digitSum?\nYou can use map to store digitSum as key and number itself as value. \nSo you may think there can be so many numbers with digitSum upto ```ith``` index.\nBut you want your answer to be max . So you will use maximum number with digitSum.That\'s why you need to store only max number whose digit sum=digitSum.**\n\n```\nclass Solution {\npublic:\n    int maximumSum(vector<int>& nums) {\n        int ans=-1, sz=nums.size();\n        unordered_map<int,int>mp;\n        for(auto & i:nums){\n            string s=to_string(i);\n            int sum=0;\n            for(auto & ch:s)\n                sum+=(ch-\'0\');\n            if(mp.count(sum))\n                ans=max(ans,i+mp[sum]);\n            mp[sum]=max(i,mp[sum]);\n        }\n        return ans;\n    }\n};\n```\nDo **UPVOTE** if it helps :)
['C']