Smart Approach
//Step 1 : sort in non-increasing order\n//Step 2 : store digit sum in map vector\n//Step 3 : iterate map ---> if size of vector is greater than 1 then do opera
//Step 1 : sort in non-increasing order\n//Step 2 : store digit sum in map vector\n//Step 3 : iterate map ---> if size of vector is greater than 1 then do operations , otherwise no operations\n//step 4 : return maximum value calculated above ;\nclass Solution\n{\npublic:\n    int sum(int x)\n    {\n        int n =0;\n        while(x>0)\n        {\n            n+=(x%10);\n            x/=10;\n        }\n        return n;\n    }\n    int maximumSum(vector<int>& nums)\n    {\n        sort(nums.begin(),nums.end(),greater<int> ());\n        \n        map<int,vector<int>> mp;\n        for(int i=0; i<nums.size();i++)\n        {\n            int x = sum(nums[i]);\n            mp[x].push_back(nums[i]);\n        }\n        \n        int maxi = -1;\n        for(auto it : mp)\n        {\n            if(it.second.size()<=1) continue;\n            vector<int> temp = it.second;\n            maxi = max(maxi,(temp[0]+temp[1]));\n        }\n        return maxi;\n    }\n};
['Sorting']