Easy Map Solution C++ 
IntuitionFind the elements with same digit sum using unordered_map and keep track of their sums, if there are more than two elements with the same, keep the max
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Find the elements with same digit sum using unordered_map and keep track of their sums, if there are more than two elements with the same, keep the max two in the map.
Return the max sum , if there are no two elements with the same digit sum, return -1;

# Approach
<!-- Describe your approach to solving the problem. -->
Use unordered map<int,pair<int,int>>, run a loop find the digit sum, if the digit sum is not present in the map, put the sum int the map and the number in the first of the pair and -1 in the second of the pair. If it is already present, if the second of that sum is -1 put the number in the second and check mx=max(mx,mp[sum].first,mp[sum].second), Else if the second is filled, find the smaller of the two elements and replace it with our number if the smaller one is smaller than the number, again find the max of sum. Return mx, or -1(used a flag to check if two numbers have same digit sum);
# Complexity
- Time complexity:O(N*N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(

- Space complexity:O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int sum(int a){
        int s=0;
        while(a!=0){
            int r=a%10;
            a=a/10;
            s+=r;
        }
        return s;
    }
    int maximumSum(vector<int>& nums) {
        unordered_map<int,pair<int,int>> mp;
        int mx=0;
        bool flag=false;
        for(int i=0;i<nums.size();i++){
            int s=sum(nums[i]);
            if(mp.find(s)!=mp.end()){
                if(mp[s].second==-1){
                    flag=true;
                    mp[s].second=nums[i];
                    mx=max(mx,mp[s].first+mp[s].second);
                }
                else{
                    if(mp[s].first>=mp[s].second and nums[i]>mp[s].second){
                        mp[s].second=nums[i];
                        mx=max(mx,mp[s].second+mp[s].first);
                    }
                    else if(mp[s].second>=mp[s].first and nums[i]>mp[s].first){
                        mp[s].first=nums[i];
                        mx=max(mx,mp[s].second+mp[s].first);
                    }
                }
            }
            else{
                mp[s].first=nums[i];
                mp[s].second=-1;
            }
        }
        if(!flag){
            return -1;
        }
        return mx;
    }
};
```
['C++']