Easiest Approach | O(n) | Beginner Friendly | Beats 100% 🥷🏻🔥💨
IntuitionUse a dictionary to map the sum with corresponding nums[i]. If the current sum exists in the dictionary, then the pairs satisfy the condition and we ca
# Intuition
Use a dictionary to map the sum with corresponding nums[i]. If the current sum exists in the dictionary, then the pairs satisfy the condition and we can update our maxsum accordingly.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
Use a dictionary to map the sum with corresponding nums[i]. If the current sum exists in the dictionary, then the pairs satisfy the condition and we can update our maxsum accordingly.
<!-- 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)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    public int MaximumSum(int[] nums) {
        int n = nums.Length;
        //Array.Sort(nums);
        Dictionary<int, int> sums = new();
        int max = -1;

        for(int i=0; i<n; i++){
            int dsum = 0;
            int x = nums[i];
            while(x!=0){
                dsum += x % 10;
                x/= 10;
            }
            if(sums.ContainsKey(dsum)){
                if(sums[dsum] + nums[i] > max){
                    max = sums[dsum] + nums[i];
                }
                sums[dsum] = sums[dsum] > nums[i] ? sums[dsum] : nums[i];
            }
            else{
                sums[dsum] = nums[i];
            }
        }

        return max;
    }
}
```
['Array', 'Hash Table', 'Sorting', 'Heap (Priority Queue)', 'Java', 'C#', 'MS SQL Server']