Permutation of `m`, with explanation
Thought process:\nFind match of students and mentors is the same as keep students in original order, but match them with permutated mentors order.\ni.e. m = 3, 
Thought process:\nFind match of students and mentors is the same as keep students in original order, but match them with permutated mentors order.\ni.e. m = 3, perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1]]\n\nTime: O(m! + m!*n*m)\nSpace: O(m!)\n\n```\nclass Solution(object):\n    def maxCompatibilitySum(self, students, mentors):\n\t\tm = len(students)\n        n = len(students[0])\n        ori = [i for i in range(m)]\n        perms = []\n        def perm(ori, i):\n            if i == len(ori): \n                perms.append(ori[:])\n                return\n            for j in range(i, len(ori)):\n                ori[j], ori[i] = ori[i], ori[j]\n                perm(ori, i+1)\n                ori[j], ori[i] = ori[i], ori[j]\n        perm(ori, 0)\n        res = 0\n        for p in perms:\n            cur = 0\n            for i in range(m):\n                match = p[i]\n                for j in range(n):\n                    cur += 1 if students[i][j] == mentors[match][j] else 0\n            res = max(res, cur)\n        return res
[]