Easiest map approach O(N) time and space
IntuitionThe key observation is that two numbers should have the same sum of digits to be considered. Instead of checking all pairs (which would be inefficient)
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The key observation is that two numbers should have the same sum of digits to be considered. Instead of checking all pairs (which would be inefficient), we can use a hash map (unordered_map<int, int>) to store the maximum number encountered for each digit sum.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Use a hash map (unordered_map<int, int> m) where:
The key is the sum of digits of a number.
The value is the maximum number encountered so far for that sum.
2. Iterate through nums:
Compute the sum of digits of each number.
If the sum of digits exists in the map, update the maximum possible sum (s).
Update the stored maximum value for that digit sum.
3. Return the maximum sum found.
# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class Solution {
public:
    int maximumSum(vector<int>& nums) {
        unordered_map<int,int>m;
        int s=-1;
        int digit=0;
        int x;
        for(auto num: nums){
            x=num;
            digit=0;
            while(x!=0){
                digit+=x%10;
                x/=10;
            }
            if(m.count(digit)){
                s=max(s,m[digit]+num);
                m[digit]=max(m[digit],num);
            }
            else m[digit]=num;
        }
        return s;
    }
};
```
['Array', 'Hash Table', 'C', 'Sorting', 'Heap (Priority Queue)', 'C++']