/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 143ms 13.461 MiB
#2 Wrong Answer 140ms 13.445 MiB

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-11 02:32:08
Judged By
Score
0
Total Time
143ms
Peak Memory
13.461 MiB