simple optimized approach using python
Complexity

Time complexity:
  O(n log n)


Space complexity:
  O(n log n).

Code


# Complexity
- Time complexity:

        O(n log n)

- Space complexity:

        O(n log n).

# Code
```python []
class Solution(object):
    def maximumSum(self, nums):
        def digitSum(n):
            return sum(int(a) for a in str(n))

        nump = [(digitSum(num), num) for num in nums]
        nump.sort() 

        maxx=-1
        for i in range(1, len(nump)):
            if nump[i][0] == nump[i - 1][0]:  
                maxx = max(maxx, nump[i][1] + nump[i - 1][1])

        return maxx

```
['Array', 'Hash Table', 'Sorting', 'Heap (Priority Queue)', 'Python', 'Python3']