Beats 90% 🚀| Easy To Understand ✅| No HashMap ❌
IntuitionThe problem requires finding the maximum sum of two numbers in the array that have the same digit sum.
The digit sum of a number is the sum of all its
# Intuition
**The problem requires finding the maximum sum of two numbers in the array that have the same digit sum.**

- The digit sum of a number is the sum of all its digits (eg for num = 123, digit sum = 1 + 2 + 3 = 6).
- If two numbers share the same digit sum, we consider their sum and track the maximum possible sum.
- We use an array (arr[90], since the max digit sum for 999999999 is 81) to store the largest number seen for each digit sum.

# Approach
## **Digit Sum Calculation:**

- Define a helper function that calculates the sum of digits of num.
## **Tracking the Largest Pair:**

- Maintain an array arr[90], initialized to -1, to store the largest number for each digit sum.
- Iterate over nums:
    - Compute the digit sum of the current number.
    - If another number with the same digit sum exists in arr,      update   the maxi (maximum sum of such a pair).
    - Update arr[sum] to store the maximum value seen so far for this digit sum.
## **Return Result:**

- If no valid pair exists, return -1. Otherwise, return the maximum sum found.

# Complexity
- Time complexity:
 O(nlogm) 

- Space complexity:
 O(1)

# Code
```cpp []
class Solution {
public:
    int helper(int num) {
        int sum = 0;
        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
        return sum;
    }
    int maximumSum(vector<int>& nums) {
        vector<int> arr(90,-1);
        int maxi = -1; 
        for (auto num : nums) {
            int sum = helper(num);
            if (arr[sum] != -1) {
                maxi = max(maxi, arr[sum] + num);
                arr[sum] = max(arr[sum], num);
            } else {
                arr[sum] = num;
            }
        }
        return maxi;
    }
};
```
['C++']