JAVA | Simple DFS
\nclass Solution {\n    int[][] students;\n    int[][] mentors;\n    int len = 0;\n    int res = 0;\n    public int maxCompatibilitySum(int[][] _students, int[]
```\nclass Solution {\n    int[][] students;\n    int[][] mentors;\n    int len = 0;\n    int res = 0;\n    public int maxCompatibilitySum(int[][] _students, int[][] _mentors) {        \n        students = _students;\n        mentors = _mentors;\n        if(students == null || students.length == 0 || mentors == null || mentors.length == 0) {\n            return 0;\n        }\n        \n        len = students.length;\n        dfs(0, new ArrayList<>(), new HashSet<Integer>());\n        return res;\n    }\n    \n    private void dfs(int index, ArrayList<int[]> list, HashSet<Integer> set) {\n        if(list.size() == len) {\n             //System.out.println(list.size());\n            int temp = score(list);\n            res = Math.max(temp, res);\n        }\n        \n        for(int i = 0; i < len; i++) {\n            if(!set.contains(i)) {\n                set.add(i);\n                list.add(mentors[i]);\n                dfs(i + 1, list, set);\n                list.remove(mentors[i]); \n                set.remove(i);\n            }\n        }   \n    }\n\n    private int score(ArrayList<int[]> list) {\n        int count = 0;\n        for(int i = 0; i < list.size(); i++) {\n            int[] student = students[i];\n            int[] mentor = list.get(i);\n            for(int p = 0; p < student.length; p++) {\n                if(student[p] == mentor[p]) {\n                    count++;\n                }\n            }\n        }\n        return count;\n    }             \n}\n```
[]