C++ | |  Map<Multi set>
Using multimap for storing element (+Duplicate) in sorted order\nCalc the digit sum of every element \nsimultaneously store the sum and the elemnt in map of mul
**Using multimap for storing element (+Duplicate) in sorted order**\n**Calc the digit sum of every element \nsimultaneously store the sum and the elemnt in map of multiset**\n\n**element with same sum would be inserted in same multimap**\n\n**Traverse in map \n-> if the freq is greater equal to 2\n-> take the sum of last 2 elements form multimap**\n```\nclass Solution {\nprivate:\n\t// For digit Sum\n    int sum(int n){\n        int ans = 0;\n        while(n>0){\n            ans += n%10;\n            n /= 10;\n        }\n        return ans;\n    }\npublic:\n    int maximumSum(vector<int>& nums) {\n        map<int,multiset<int>> m1;\n        long long maxi = 0, mn = INT_MIN;\n        \n\t\t//  store digit sum with its corrreponding element\n        for(int i=0;i<nums.size();i++){\n            int s = sum(nums[i]);\n            m1[s].insert(nums[i]);\n        }\n        \n\t\t//  traverse through map\n        for(auto it = m1.rbegin();it!=m1.rend();it++){\n            if(it->second.size()>=2){        // Atleast 2 elements\n                maxi = 0;\n                auto i = it->second.end();\n                maxi += *(--i);                // last element\n                maxi += *(--i);                // second last element\n                mn = max(maxi,mn);\n            }\n        }\n        if(maxi==0)     return -1;                // if the is not such pair with same digit sum\n        return max(maxi,mn);\n    }\n};\n```\n![image](https://assets.leetcode.com/users/images/15a90cc2-926f-4561-be43-45388b4c6b71_1658041985.0471632.png)\n\n
['C']