SIMPLE MAX-HEAP + MAP C++ SOLUTION DRY RUN
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n//nums = [18,43,36,13,7]  (ans = 54)\n\n// For 18: Sum of digits = 1 + 8 = 9. digitSumMap[9].push(18)\n// For 43: Sum of digits = 4 + 3 = 7. digitSumMap[7].push(43)\n// For 36: Sum of digits = 3 + 6 = 9. digitSumMap[9].push(36)\n// For 13: Sum of digits = 1 + 3 = 4. digitSumMap[4].push(13)\n// For 7: Sum of digits = 7. digitSumMap[7].push(7)\n// The map now looks like:\n// 9 -> [36, 18] (priority queue orders them as 36 being the top)\n// 7 -> [43, 7]\n// 4 -> [13]\n// 3. Calculating Maximum Sum:\n// For key 9: The queue has two elements. first = 36, second = 18. Sum = 36 + 18 = 54.\n// For key 7: The queue has two elements. first = 43, second = 7. Sum = 43 + 7 = 50.\n// For key 4: The queue has only one element, so it\'s skipped.\n// 4. Finding the Maximum: The maximum of all valid sums is max(54, 50) = 54.\nclass Solution {\npublic:\n    int sumOfDigits(int n) {\n        int sum = 0;\n        while (n > 0) {\n            sum += n % 10;\n            n /= 10;\n        }\n        return sum;\n    }\n\n    int maximumSum(vector<int>& nums) {\n        map<int,priority_queue<int>>digitSumMap;\n        for(auto&num : nums){\n            int digitSum = sumOfDigits(num);\n            digitSumMap[digitSum].push(num);\n        }\n        int maxSum = -1;\n        for (auto&x : digitSumMap){\n            if (x.second.size() > 1) {\n                int first = x.second.top();\n                x.second.pop();\n                int second = x.second.top();\n                maxSum = max(maxSum, first + second);\n            }\n        }\n\n        return maxSum;\n    }\n};\n```
['C++']