1ms 100% JAVA BackTracking + BitMask solution
\n        public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n            int n = students.length;\n            return helper(0, 0, students, m
```\n        public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n            int n = students.length;\n            return helper(0, 0, students, mentors, new Integer[n][1 << n]);\n        }\n\n\n        private int helper(int pos, int mask, int[][] students, int[][] mentors, Integer[][] memo) {\n            int n = students.length;\n            if (mask == (1 << n) - 1)\n                return 0;\n            if (memo[pos][mask] != null)\n                return memo[pos][mask];\n\n            int maxScore = 0;\n            for (int i = 0; i < n; i++) {\n                if ((mask & (1 << i)) == 0) {\n                    int score = getScore(students[pos], mentors[i]);\n                    maxScore = Math.max(maxScore, score + helper(pos + 1, (mask | (1 << i)), students, mentors, memo));\n                }\n            }\n\n            return memo[pos][mask] = maxScore;\n        }\n\n        private int getScore(int[] a, int[] b) {\n            int count = 0;\n            for (int i = 0; i < b.length; i++)\n                if (a[i] == b[i]) count++;\n            return count;\n        }\n```
[]