C++ Solution || Hash Map Approach || Comments for easy understanding
Code
>

# Code
```cpp []
class Solution {
public:
    // Function to calculate the sum of digits of a number
    int digitSum(int number) {
        int sum = 0;
        while (number > 0) {
            sum += number % 10; // Extract the last digit and add to sum
            number /= 10;       // Remove the last digit
        }
        return sum;
    }

    int maximumSum(vector<int>& nums) {
        int ans = -1; // Default answer in case no valid pair is found
        map<int, vector<int>> mp; // Map to store numbers grouped by their digit sum

        // Group numbers by their digit sum
        for (int i = 0; i < nums.size(); i++) {

            mp[digitSum(nums[i])].push_back(nums[i]); // Store the number in the corresponding sum group
        }

        // Iterate through the map to find the maximum pair sum
        for (auto x : mp) {
            if (x.second.size() >1) { 
                // Only consider groups with at least 2 numbers
                sort(x.second.rbegin(),x.second.rend()); // Sort numbers in descending order
                ans =max(ans,x.second[0] + x.second[1]); // Take the sum of the top two numbers
            }
        }

        return ans; // Return the maximum sum found
    }
};
```
['C++']