Easy to understand 🔥, Beginner Friendly🥳 , 100% Accepted💯 , 3 Solutions🙏🏻.
Approach
write function which will give us sum of a number.
create vector ANS having data type "pair" , in which we will store nums[i] sum and nums[i] as pair.

# Approach
<!-- Describe your approach to solving the problem. -->
1. write function which will give us sum of a number.
2. create vector ANS having data type "pair" , in which we will store nums[i] sum and nums[i] as pair. 
3. then simply traverse array and fill our ANS  vector.
4. sort the vector and we will get all pair having same digit sum together.
5. use 2 loops and store there num[i] sum in a variable which we gonna return in end.
# Complexity
- Time complexity:
O(n^2)
- Space complexity:
O(n)
# Code
```cpp [

class Solution {
public:

    int ccount(int n ){
        int ans = 0;
        while(n){
            int x = n%10;
            ans+=x;
            n=n/10;
        }
        return ans;

    }

    int maximumSum(vector<int>& nums) {
        int n = nums.size();
        vector<pair<int, int>>ans;
        for(int i =0; i<n;i++){
            int a = ccount(nums[i]);
            pair p = {a, nums[i]};
            ans.push_back(p);
        }
        sort(ans.begin(), ans.end());

        int maxi = -1;


        for(int i =0; i<n; i++){
            for(int j = i+1; j<n; j++){
                if(ans[i].first == ans[j].first){
                    maxi = max(maxi , ans[i].second+ans[j].second);
                }
                else
                break;
            }
            
        }
        return maxi;

    }
};
```

# Approach
1. used same logic as above code , just optimized solution by remove 2 loops and use only 1 loop
2. we can traverse ANS from back because last pair will give as maximum value ( which we need in problem).
# Complexity
- Time complexity:
O(nlog(n))

- Space complexity:
O(n)

# Code
```cpp [

class Solution {
public:

    int ccount(int n ){
        int ans = 0;
        while(n){
            int x = n%10;
            ans+=x;
            n=n/10;
        }
        return ans;

    }

    int maximumSum(vector<int>& nums) {
        int n = nums.size();
        vector<pair<int, int>>ans;
        for(int i =0; i<n;i++){
            int a = ccount(nums[i]);
            pair p = {a, nums[i]};
            ans.push_back(p);
        }
        sort(ans.begin(), ans.end());

        int maxi = -1;


        for(int i =n-1; i>0; i--){
                if(ans[i].first == ans[i-1].first){
                    maxi = max(maxi , ans[i].second+ans[i-1].second);
                }
        }
        return maxi;

    }
};
```


# Approach
1. we are using priority_queue instead of vector , so that we don't have to sort the array.

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```cpp [
class Solution {
public:

    int ccount(int n ){
        int ans = 0;
        while(n){
            int x = n%10;
            ans+=x;
            n=n/10;
        }
        return ans;

    }

    int maximumSum(vector<int>& nums) {
        int n = nums.size();
        vector<pair<int, int>>ans;
        for(int i =0; i<n;i++){
            int a = ccount(nums[i]);
            pair p = {a, nums[i]};
            ans.push_back(p);
        }
        sort(ans.begin(), ans.end());

        int maxi = -1;


        for(int i =n-1; i>0; i--){
                if(ans[i].first == ans[i-1].first){
                    maxi = max(maxi , ans[i].second+ans[i-1].second);
                }
        }
        return maxi;

    }
};
```
['C++']