Easy O(n) solution in C++ using map and priority queue..
IntuitionWe have to make the group of elements having the sum of the digits as same . Then we have to return the pair belonging to the same group and having the
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We have to make the group of elements having the sum of the digits as same . Then we have to return the pair belonging to the same group and having the maximum sum.
This can be done if we group the elements with same sum of digits in a map.
# Approach
<!-- Describe your approach to solving the problem. -->
The map we will be using is of type int-->priority_queue.
The reason to use this is to get the largest element of that group easily.
We will try the sum of two largest elements of the each group and return the maximum sum.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(n)$$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$$O(n)$$
# Code
```cpp []
class Solution {
public:
    int maximumSum(vector<int>& nums) {
        unordered_map<int,priority_queue<int>>mp;
        for(int i=0;i<nums.size();i++)
        {
            int sum=0;
            int n=nums[i];
            while(n>0){
                int last=n%10;
                sum+=last;
                n=n/10;
            }
            mp[sum].push(nums[i]);
        }

        int maxi=-1;
        for(auto it : mp)
        {
            if(it.second.size()>=2)
            {
                int last=it.second.top();
                it.second.pop();
                int secondLast=it.second.top();
                maxi=max(maxi,last+secondLast);
            }
        }
        return maxi;
    }
};
```
['C++']