✅ FIRST TWO OF SAME KEY + Priority Queue Approach || Intuition
First by seeing I got intution for TRIE because the question was stating max pair sum which is same as Max-xor pair.\n    \nBut the catch here is they have give
First by seeing I got intution for TRIE because the question was stating max pair sum which is same as Max-xor pair.\n    \nBut the catch here is they have given a KEY which should be common between the two pair i.e sum of digits should be same.\n    \nSo now i thought of making map.\nAnd then I thought of putting the element in their respective sum of digit group.\nAnd for every group we know only two will give maximum sum i.e first two largest.\nFor that purpose I sorted the elements in decreasing order.\nAnd just got maximum of sum of first two elements of every key.\n\n**Priority Queue Approach**:\nWe always want two max value element having same sum of digits which will give us max_sum.\nSo for that I used a priority_queue using which I will restrict the size to 2 every time. In this way I will have top two at last.\nAnd now we just retrace and get top two with maximum sum.\n\n![image](https://assets.leetcode.com/users/images/0bb2d9b3-f973-4462-8b42-8dc978961d20_1658046663.3462887.png)\n\n\n**C++ using priority Queue**\n    \n\t//Calculate sum of digits of a given number\n    int count(int num){\n        int digitSum = 0;\n        while(num > 0) {\n            digitSum += num % 10;\n            num /= 10;\n        }\n        return digitSum;\n    }\n    \n    int maximumSum(vector<int>& A) {\n        vector<priority_queue<int,vector<int>,greater<int>>> mp(82);\n        \n        //put in respective sum of digits keys  \n        for(auto i:A){\n            int cnt= count(i);\n\t\t\t//{Push and pop will be constant because the size of queue will be atmost 2 always}\n            mp[cnt].push(i);\n\t\t\t//restrict the size to 2 always\n            if(mp[cnt].size()>2) mp[cnt].pop();\n        }\n    \n        //then first two of every are suitable for giving maximum sum\n        long max_sum=0;\n        for(auto f:mp){\n            if(f.size()<2) continue;\n\t\t\t//get top two\n            int first=  f.top();  f.pop();\n            int second= f.top();\n            long pair_sum= first+second;\n            max_sum= max(max_sum,pair_sum); \n        }\n        \n        return max_sum==0? -1 : max_sum;\n    }\n**Time** - O(N)\n**Space** - O(82) , at masx the sum of digit of any number will 82 only, not more than that.\n\n**C++ using Sorting**\n\n      int maximumSum(vector<int>& A) {\n        \n        //Calculate sum of digits of a given number\n        auto count=[&](int num){\n            int sum=0;\n            for(;num>0;num/10) sum+= num%10;\n            return sum;\n        };\n        \n        //sort in decreasing order\n        sort(rbegin(A),rend(A));\n        \n        //map which \n        unordered_map<int,vector<int>> mp;\n        \n        //put in respective sum of digits keys\n        for(auto i:A) mp[count(i)].push_back(i);\n        \n        //then first two of every are suitable for giving maximum sum\n        long max_sum=0;\n        for(auto &[i,v]:mp){\n            if(v.size()>=2) max_sum= max((long)max_sum,(long)(v[0]+v[1])); \n        }\n        \n        return max_sum==0? -1 : max_sum;\n        \n    }
['C', 'Sorting', 'Heap (Priority Queue)']