Java | Simple DFS | Check all permutations
\nclass Solution {\n    public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n        return dfs(students,mentors,new boolean[mentors.length],0);
```\nclass Solution {\n    public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n        return dfs(students,mentors,new boolean[mentors.length],0);\n    }\n    int dfs(int[][] s,int[][] m,boolean[] b,int o){\n        int sum=0;\n        if(o==s.length){\n            return 0;\n        }\n        for(int i=0; i<m.length; i++){\n            if(b[i]){\n                continue;\n            }\n            int ss=0;\n            for(int j=0; j<m[0].length; j++){\n                if(s[o][j]==m[i][j]){\n                    ss++;\n                }\n            }\n            b[i]=true;\n            sum=Math.max(sum,ss+dfs(s,m,b,o+1));\n            b[i]=false;\n        }\n        return sum;\n    }\n}\n```
['Depth-First Search', 'Java']