Using Hashing and Pair | Just Do It 🙂‍↔️
Complexity

Time complexity:
O(N*LogN)


Space complexity:
O(N)

CodeAsk any doubt !!!Reach out to me 😊👇
🔗 https://tushar-bhardwaj.vercel.app/

# Complexity
- Time complexity:
```O(N*LogN)```

- Space complexity:
```O(N)```

# Code
```cpp []
class Solution {
public:
    // to count the digit sum of the no.
    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,pair<int,int>>mpp;
        sort(nums.rbegin(),nums.rend()); // To get largest digit before handed
        int ans=-1;
        for(int i=0;i<nums.size();i++){
            int temp=digit(nums[i]);
            if(mpp[temp].second==1){ // Same count found
                ans=max(ans,nums[i]+mpp[temp].first);
                mpp[temp].second=-1; // Blocked 
        // [as all the values that will come after this will have the smaller value than this number as we have already sorted the array in decreasing order]
            }
            else if(mpp[temp].second!=-1){
                mpp[temp].first=nums[i]; // Value stored
                mpp[temp].second++;
            }
        }
        return ans;
    }
};
```

![anonupvote.jpeg](https://assets.leetcode.com/users/images/bf7ce48f-1a34-404c-8610-410d43112c2c_1720413559.1746094.jpeg)
# Ask any doubt !!!
Reach out to me 😊👇
🔗 https://tushar-bhardwaj.vercel.app/
['Array', 'Hash Table', 'Greedy', 'Sorting', 'C++']