Easy HashMaps with PQ solution✅✅
IntuitionThe problem requires finding the maximum sum of two numbers in an array that share the same sum of digits.
To achieve this, we need to group numbers by
# Intuition
The problem requires finding the maximum sum of two numbers in an array that share the same sum of digits. 
To achieve this, we need to group numbers by their digit sum and then determine the maximum sum of two 
numbers within the same group.

# Approach
1. Create a function `getSum(int n)` to compute the sum of digits of a given number.
2. Use a `map<int, priority_queue<int>>` to group numbers by their digit sum while maintaining a max heap
   (priority queue) for each sum.
3. Iterate through the array and populate the map.
4. Traverse the map and check if any group has at least two elements.
5. Extract the two largest elements from the priority queue and compute their sum.
6. Track the maximum sum encountered and return it as the result.

# Complexity
- Time Complexity: **O(n log n)** 
  - Iterating through the array takes **O(n)**.
  - Inserting into a priority queue takes **O(log n)**, leading to an overall **O(n log n)** complexity.
- Space Complexity: **O(n)**
  - The map stores the numbers, leading to **O(n)** space usage.

# Code
```cpp []
class Solution {
public:
    int getSum(int n) {
        int sum = 0;
        while (n > 0) {
            sum += (n % 10);
            n /= 10;
        }
        return sum;
    }

    int maximumSum(vector<int>& nums) {
        map<int, priority_queue<int>> mp;
        for (auto it : nums) {
            int sum = getSum(it);
            mp[sum].push(it);
        }

        long long maxi = -1;
        for (auto it : mp) {
            auto pq = it.second;
            if (pq.size() < 2) continue;
            int cnt = 0;
            long long sum = 0;
            while (!pq.empty() && cnt < 2) {
                sum += pq.top();
                pq.pop();
                cnt++;
            }
            maxi = max(maxi, sum);
        }
        return maxi;
    }
};
```
```Java []
import java.util.*;

class Solution {
    private int getSum(int n) {
        int sum = 0;
        while (n > 0) {
            sum += (n % 10);
            n /= 10;
        }
        return sum;
    }

    public int maximumSum(int[] nums) {
        Map<Integer, PriorityQueue<Integer>> map = new HashMap<>();
        for (int num : nums) {
            int sum = getSum(num);
            map.putIfAbsent(sum, new PriorityQueue<>(Collections.reverseOrder()));
            map.get(sum).offer(num);
        }

        long maxSum = -1;
        for (PriorityQueue<Integer> pq : map.values()) {
            if (pq.size() < 2) continue;
            long sum = pq.poll() + pq.poll();
            maxSum = Math.max(maxSum, sum);
        }
        return (int) maxSum;
    }
}

```
```Python []
from collections import defaultdict
import heapq

class Solution:
    def getSum(self, n: int) -> int:
        return sum(int(digit) for digit in str(n))

    def maximumSum(self, nums: list[int]) -> int:
        num_map = defaultdict(list)
        for num in nums:
            digit_sum = self.getSum(num)
            heapq.heappush(num_map[digit_sum], -num)

        max_sum = -1
        for heap in num_map.values():
            if len(heap) < 2:
                continue
            max_sum = max(max_sum, -heapq.heappop(heap) - heapq.heappop(heap))

        return max_sum

```
['Hash Table', 'Sorting', 'Heap (Priority Queue)', 'Python', 'C++', 'Java', 'Python3']