Java - 74 ms - permutation - beats 100% time and 100% memory
\nclass Solution {\n    private int max;\n    \n    public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n        max = 0;\n        permute(stude
```\nclass Solution {\n    private int max;\n    \n    public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n        max = 0;\n        permute(students, mentors, 0, students.length);\n        return max;\n    }\n    \n    private void permute(int[][] students, int[][] mentors, int index, int N){\n        if(index == N){\n            int score = 0;\n            for(int i = 0; i < N; i++){\n                score += compatibility(students[i], mentors[i]);\n            }\n            \n            max = Math.max(max, score);\n        }else{\n            for(int i = index; i < N; i++){\n                swap(students, index, i);\n                permute(students, mentors, index + 1, N);\n                swap(students, index, i);\n            }\n        }\n    }\n    \n    private void swap(int[][] students, int i, int j){\n        int[] temp = students[i];\n        students[i] = students[j];\n        students[j] = temp;\n    }\n    \n    private int compatibility(int[] a, int[] b){\n        int i, N = a.length;\n        int sum = 0;\n        \n        for(i = 0; i < N; i++){\n            if(a[i] == b[i]){\n                ++sum;\n            }\n        }\n        \n        return sum;\n    }\n}\n```
[]