1
var maxCompatibilitySum = function (students, mentors) {2
const m = students.length;3
const n = students[0].length;7
dfs(0, (1 << m) - 1, 0);11
function dfs(studentIdx, bitmask, scoreTally) {12
if (studentIdx === m) {13
max = Math.max(max, scoreTally);18
for (let mentorIdx = 0; mentorIdx < m; ++mentorIdx) {19
if (bitmask & (1 << mentorIdx)) {20
const matchScore = hammingDistance(24
const setMask = bitmask ^ (1 << mentorIdx);26
dfs(studentIdx + 1, setMask, scoreTally + matchScore);33
function hammingDistance(studentsAnswers, mentorsAnswers) {36
for (let j = 0; j < n; ++j) {37
if (studentsAnswers[j] === mentorsAnswers[j]) ++matches;