Skip to content

Commit 74b837e

Browse files
committed
Runtime: 239 ms (Top 46.15%) | Memory: 42.4 MB (Top 84.62%)
1 parent a5a7d4d commit 74b837e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1+
// Runtime: 239 ms (Top 46.15%) | Memory: 42.4 MB (Top 84.62%)
12
var maxCompatibilitySum = function(students, mentors) {
23
const m = students.length;
34
const n = students[0].length;
4-
5+
56
let max = 0;
6-
7+
78
dfs(0, (1 << m) - 1, 0);
8-
9+
910
return max;
10-
11+
1112
function dfs(studentIdx, bitmask, scoreTally) {
1213
if (studentIdx === m) {
1314
max = Math.max(max, scoreTally);
14-
15+
1516
return;
1617
}
17-
18+
1819
for (let mentorIdx = 0; mentorIdx < m; ++mentorIdx) {
1920
if (bitmask & (1 << mentorIdx)) {
2021
const matchScore = hammingDistance(students[studentIdx], mentors[mentorIdx]);
2122
const setMask = bitmask ^ (1 << mentorIdx);
22-
23+
2324
dfs(studentIdx + 1, setMask, scoreTally + matchScore);
2425
}
2526
}
26-
27+
2728
return;
2829
}
29-
30+
3031
function hammingDistance(studentsAnswers, mentorsAnswers) {
3132
let matches = 0;
32-
33+
3334
for (let j = 0; j < n; ++j) {
3435
if (studentsAnswers[j] === mentorsAnswers[j]) ++matches;
3536
}
36-
37+
3738
return matches;
3839
}
39-
};
40+
};

0 commit comments

Comments
 (0)