Wrong Answer
Code
function maximumMex(T, testCases) {
const results = [];
for (let t = 0; t < T; t++) {
const [N, array] = testCases[t];
// Convert array to a set for O(1) lookups
const numSet = new Set(array);
// Find the smallest non-negative integer not in the set (MEX)
let mex = 0;
while (numSet.has(mex)) {
mex++;
}
results.push(mex);
}
return results.join("\n");
}
// Example usage:
const T = 3;
const testCases = [
[3, [0, 1, 2]],
[4, [0, 1, 1, 1]],
[3, [0, 3, 3]]
];
console.log(maximumMex(T, testCases));
Information
- Submit By
- Type
- Submission
- Problem
- P1114 Maximize the MEX
- Contest
- Brain Booster #7
- Language
- JavaScript (Node.js v18.19.1)
- Submit At
- 2024-11-05 14:55:03
- Judged At
- 2024-11-05 14:55:03
- Judged By
- Score
- 0
- Total Time
- 125ms
- Peak Memory
- 13.695 MiB