 Animated Explaination | Beats 100% | O(N) Time O(1) Memory | 50 Day Streak | 
Intuition
Detailed Video : 2342. Max Sum of a Pair With Equal Sum of Digits 
Storing the maximum value for a given digit sum and returning the maximum of it
App
# Intuition
- Detailed Video : [2342. Max Sum of a Pair With Equal Sum of Digits ](https://youtu.be/uj4w64hRdb4)
- Storing the maximum value for a given digit sum and returning the maximum of it 

https://youtu.be/uj4w64hRdb4

# Approach

Detailed Video : [2342. Max Sum of a Pair With Equal Sum of Digits ](https://youtu.be/uj4w64hRdb4)

1. Create an integer array of size 90 because input nums[i]<10^9 creating a max of digit sum as 81 . This array shall store the maximum value for the given digit sum.
2. Traverse through the Array 
     - Calculate the current digitSum 
     - Check if it already exists , if yes update the answer =  max(answer , curr+existing); 
     - Update the max(curr, existing) in the array for the same digit sum
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(N)

- Space complexity:
O(1) 

# Code
```java []
class Solution {
    public int maximumSum(int[] nums) {
        int[] map = new int[90];
        int ans = -1;
        for(int i=0;i<nums.length;i++){
            int sum = sumOfDigit(nums[i]);
            if(map[sum]!=0) ans=Math.max(ans,nums[i]+map[sum]);
            map[sum] = Math.max(nums[i],map[sum]);
        }
        return ans;
    }

    public int sumOfDigit(int n){
        int sum=0;
        while(n>0){sum+=(n%10);n/=10;}
        return sum;
    }
}
```
['Math', 'Counting', 'C++', 'Java', 'Python3']