Fast & Clean | O(n) | HashMap + Top 2 Tracking | 100% BEATS
IntuitionThe problem requires finding two numbers in the array that have the same sum of digits and maximizing their sum. The key observation is that numbers wi
# Intuition
The problem requires finding two numbers in the array that have the same sum of digits and maximizing their sum. The key observation is that numbers with the same digit sum should be grouped together, and we should keep track of the two largest numbers for each sum of digits.

# Approach
1. Compute the digit sum of each number using a helper function numsum().
2. Use a hash map (unordered_map<int, pair<int, int>>) to store the two largest numbers for each digit sum.
    - The key is the digit sum.
    - The value is a pair of the two largest numbers that have this digit sum.
3. Iterate through nums:
    - Compute the digit sum of nums[i].
    - Check if this sum exists in the map:
        - If yes, update the top two largest numbers for this sum.
        - If not, store the first number and initialize the second as -1.
4. Update the maximum possible sum whenever a valid pair exists.
5. Return the result after checking all numbers.

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)

# Code
```cpp []
class Solution {
public:
    int numsum(int digit){
        int tmp=0;
        while(digit>0)
        {
            tmp+=digit%10;
            digit = digit/10;
        }
        return tmp;
    }
    int maximumSum(vector<int>& nums) {
        int n = nums.size();
        unordered_map<int,pair<int,int>> mp;
        int ans = -1;
        
        for(int i=0;i<n;i++)
        {
            int s = numsum(nums[i]);
            auto it = mp.find(s);
            if(it != mp.end()){
                int first = it->second.first;
                int second = it->second.second;

                if(nums[i] > first){
                    second = first;
                    first = nums[i];
                }
                else if(nums[i] > second){
                    second = nums[i];
                }
                it->second = {first,second};

                if(second != -1){
                    ans = max(ans,first+second);
                }
                
            }
            else{
                mp[s] = {nums[i],-1};
            }
        }
        
    return ans;
    }
};
```
['Hash Table', 'C++']