C++ solution with explanation faster than 80%
\n//We have m different students and m different mentors. So, there are m! different ways of mapping students\n//with the mentors. This is what I\'ve done and a
```\n//We have m different students and m different mentors. So, there are m! different ways of mapping students\n//with the mentors. This is what I\'ve done and at last took the maximum of it. This is kind of brute force but \n//before that I converted every row to a binary number because bitwise operations are very fast\n\nclass Solution {\npublic:\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m = students.size();\n        int n = students[0].size();\n        \n        /*Converting the 2D vector to a 1D vector*/\n        vector<int> st(m);\n        vector<int> me(m);\n        for(int i=0; i<m; i++){\n            int num1 = 0, num2 = 0;\n            for(int j=0; j<n; j++){\n                num1*=2;\n                num1+=students[i][j];\n                num2*=2;\n                num2+=mentors[i][j];\n            }\n            st[i] = num1; //student\n            me[i] = num2; //mentor\n        }\n        /*I\'ve converted every row to a number whose binary representation is same as that of the row*/\n        \n        vector<int> perm(m); //created an array to map students to mentors\n        for(int i=0; i<m; i++) perm[i] = i; //first permutation -> 0,1,2,3,...,m\n        int res = 0; //result = maximum of all scores obtained from m! different permutations (or mappings)\n        do{\n            //this is a permutation\n            int score = 0;\n            for(int i=0; i<m; i++){\n                int k = st[i]^me[perm[i]]; //xor between student and mentor will turn OFF matching bits\n                //there are n bits in total and suppose p out of them are not matching\n                //so the score = (n-p)\n                score+=(n - __builtin_popcount(k));\n                //__builtin_popcount(...) is an inbuilt function to count the number of ON bits in a number\n            }\n            res = max(score, res);\n        }\n        while(next_permutation(perm.begin(), perm.end())); //we iterate to the next permutation (or mapping)\n        \n        return res;\n    }\n};\n```
[]