map | multiset | easy solution | very | intutive
Intuitionsince sum of digits of the numbers are repeating in the nums. we can think about map therefore create map<int,multiset<int,greater>>mpApproachtravrese
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
since sum of digits of the numbers are repeating in the nums. we can think about map therefore create map<int,multiset<int,greater<int>>>mp
# Approach
<!-- Describe your approach to solving the problem. -->
travrese the nums, find the sum of digts , insert in the map.
now travrese the map if any set in map has size > 1 find possible answer from this.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)

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

# Code
```cpp []
class Solution {
public:
    int digit(int num) {
        int ans = 0;
        while (num > 0) {
            ans += (num % 10);
            num /= 10;
        }
        return ans;
    }
    int maximumSum(vector<int>& nums) {
        unordered_map<int, multiset<int,greater<int>>> m;
        int n = nums.size();
        for (int i = 0; i < n; i++) {
            int sumdgt = digit(nums[i]);
            // cout<<sumdgt<<" ";
            m[sumdgt].insert(nums[i]);
        }
        int ans = -1;
        for (auto p : m) {
            auto s = p.second;
            if (s.size() > 1) {
                int res = 0;
                int cnt = 0;
                for (int x : s) {
                    cnt++;
                    // cout<<x<<" ";
                    res += x;
                    if(cnt == 2) break;
                }
                // cout<<endl;
                ans = max(ans, res);
            }
        }
        return ans;
    }
};
```
['Ordered Map', 'Ordered Set', 'C++']