Skip to content

Instantly share code, notes, and snippets.

@adicuco
Last active October 5, 2022 17:05
Show Gist options
  • Select an option

  • Save adicuco/d89e429d0acd0633fcde80b82b6e3346 to your computer and use it in GitHub Desktop.

Select an option

Save adicuco/d89e429d0acd0633fcde80b82b6e3346 to your computer and use it in GitHub Desktop.
100% solution for Missing Integer Task on Codility
function solution(A) {
var max = 0;
var array = [];
for (var i = 0; i < A.length; i++) {
if (A[i] > 0) {
if (A[i] > max) {
max = A[i];
}
array[A[i]] = 0;
}
}
if (max < 1) {
return 1;
}
for (var j = 1; j < max; j++) {
if (typeof array[j] === "undefined") {
return j;
}
}
return max + 1;
}
@ZeroGDrive
Copy link
Copy Markdown

`
function solution(A) {
const set = new Set(A);
let missing = 1;

while(true) {
    if (set.has(missing)) {
        missing++;
    } else {
        break;
    }
}

return missing;

}
`

@Arshad2020
Copy link
Copy Markdown

@ZeroGDrive spot on 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment