Simple & clean Solution || Java || python3 || python
IntuitionWhen ever i see a large constraint, I try to use the dictionary or HashmapApproachStore the sum of the digits in the dictionary as a key with highest e
# Intuition
When ever i see a large constraint, I try to use the dictionary or Hashmap
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
Store the sum of the digits in the dictionary as a key with highest element 
Update the max with (key and max), as we need max pair
Update the key with (current value and key), to ensure it stores max value to form max pair



<!-- Describe your approach to solving the problem. -->

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

- Space complexity:
- O(N)
- If you find helpful please up vote the solution 🥺🥺🥺🙏🏼🙏🏼🙏🏼🥰
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maximumSum(self, nums: List[int]) -> int:
        d={}
        m=-1
        for i in range(len(nums)):
            sumdigit=0
            for j in str(nums[i]):
                sumdigit+=int(j)
            if sumdigit not in d:
                d[sumdigit]=nums[i]
            else:
                m=max(d[sumdigit]+nums[i],m)
                d[sumdigit]=max(d[sumdigit],nums[i])
        return m
```
```python []
class Solution(object):
    def maximumSum(self, nums):
        d={}
        m=-1
        for i in range(len(nums)):
            sumdigit=0
            for j in str(nums[i]):
                sumdigit+=int(j)
            if sumdigit not in d:
                d[sumdigit]=nums[i]
            else:
                m=max(d[sumdigit]+nums[i],m)
                d[sumdigit]=max(d[sumdigit],nums[i])
        return m
                
```

        
```java []
class Solution {
    public int maximumSum(int[] nums) {
        int m=-1;
        HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
        for (int i=0;i<nums.length;i++){
            int key=0;
            int n=nums[i];
            while (n!=0){
                key+=n%10;
                n=n/10;
            }

            if (!map.containsKey(key)){
                map.put(key,nums[i]);
            }
            else{
                m=Math.max(m,map.get(key)+nums[i]);
                map.put(key, Math.max(map.get(key),nums[i]));
            }
        }
        return m;
    }
}
```


['Python', 'Java', 'Python3']