One of the Best approach using the Dictionary and list
IntuitionHere First we have to find out the sum of digits in other function so we can use that function repeatedly.sort the given list for easy approach
take an
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Here First we have to find out the sum of digits in other function so we can use that function repeatedly.
```
s=0
while x>0:
    s+=x%10
    x//=10
    return s
```
sort the given list for easy approach
take an empty list append the sum of digits of each element
create a empty dictionary and insert the all elements into the dictionary if the keys are repeated then add values in the list format
```

d={}
for i in range(len(l)):
    if l[i] in d:
        d[l[i]]+=[nums[i]]
    else:
        d[l[i]]=[nums[i]]
```

# Code
```python3 []
class Solution:
    def maximumSum(self, nums: List[int]) -> int:
        def su(x):
            s=0
            while x>0:
                s+=x%10
                x//=10
            return s
        num=sorted(list(set(nums)))
        m=0
        '''for i in range(len(nums)):
            k=su(nums[i])
            for j in range(i+1,len(nums)):
                p=su(nums[j])
                if k==p and m<nums[i]+nums[j]:
                    m=nums[i]+nums[j]
        if m==0:
            return -1
        return m'''
        l=[]
        for i in nums:
            l.append(su(i))
        # for i in range(len(l)):
        #     for j in range(len(l)-1,i,-1):
        #         if l[i]==l[j] and m<nums[i]+nums[j]:
        #             m=nums[i]+nums[j]
        #             break
        d={}
        for i in range(len(l)):
            if l[i] in d:
                d[l[i]]+=[nums[i]]
            else:
                d[l[i]]=[nums[i]]
        for k,v in d.items():
            if len(v)>1:
                v.sort()
                if m<v[-1]+v[-2]:
                    m=v[-1]+v[-2]
        if m==0:
            return -1
        return m
```
['Python3']