✅✅Faster || Easy To Understand || C++ Code
Backtracking\n\n Time Complexity :- O(N * N!)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n    \n    int calculate(vector<vector<int>>& students
* ***Backtracking***\n\n* ***Time Complexity :- O(N * N!)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n    \n    int calculate(vector<vector<int>>& students, vector<vector<int>>& mentors, vector<int>& arr)\n    {\n        int n = students.size();\n        \n        // find the compatability for curr_combination\n        \n        int sum = 0;\n        \n        for(int i = 0; i < n; i++)\n        {   \n            for(int j = 0; j < students[i].size(); j++)\n            {\n                if(students[i][j] == mentors[arr[i]][j])\n                    sum++;\n            }\n        }\n        \n        return sum;\n    }\n    \n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        \n        int n = students.size();\n        \n        // store the indexo of all mentors into array\n        \n        vector<int> arr(n);\n        \n        for(int i = 0; i < n; i++)\n        {\n            arr[i] = i;\n        }\n        \n        int maxi = INT_MIN;\n        \n        // for every combination of mentor find the comapatability and take maximum of it\n        \n        do\n        {\n            // calculate compatability\n            \n            int ans = calculate(students, mentors, arr);\n            \n            // update maxi\n            \n            maxi = max(maxi, ans);\n        }\n        \n        while(next_permutation(arr.begin(), arr.end()));\n        \n        return maxi;\n    }\n};\n```
['Backtracking', 'C', 'C++']