Simple C++ solution using map
IntuitionWe can use a hashmap to store the largest number corresponding to each sum of digits. This allows us to find valid pairs efficiently.Complexity
Time co
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We can use a hashmap to store the largest number corresponding to each sum of digits. This allows us to find valid pairs efficiently.

# 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) {
        int n = nums.size();
        vector<int> summ(n);
        map<long long, int> mp;
        for (int i = 0; i < n; i++) {
            string s = to_string(nums[i]);
            int n1 = s.size();
            long long sum = 0;
            for (int j = 0; j < n1; j++) {
                sum += s[j] - '0';
            }
            summ[i] = sum;
        }
        long long maxi = -1;
        for (int i = 0; i < n; i++) {
            if (mp.find(summ[i]) == mp.end()) {
                mp[summ[i]] = nums[i];
            } else {
                long long k= (long long )nums[i] + mp[summ[i]];
                maxi = max(maxi, k);
                if(nums[i]>mp[summ[i]]){
                    mp[summ[i]]=nums[i];
                }
            }
        }
        return maxi;
    }
};
```
['Hash Table', 'C++']