Swift solution
Complexity
Time complexity: O(n)

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

- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```swift []
class Solution {
    func maximumSum(_ nums: [Int]) -> Int {
        var result = -1

        var digitsSumToMaxNum = [Int: Int]()
        for num in nums {
            var itNum = num
            var digitsSum: Int = .zero
            while itNum > .zero {
                digitsSum += itNum % 10
                itNum /= 10
            }

            if let maxNum = digitsSumToMaxNum[digitsSum] {
                result = max(result, num + maxNum)
                digitsSumToMaxNum[digitsSum] = max(maxNum, num)
            } else {
                digitsSumToMaxNum[digitsSum] = num
            }
        }

        return result
    }
}

```
['Array', 'Hash Table', 'Swift']