TypeScript Missing Integer
function missingInteger(a: number[]): number {
let min = 1;
const unique = [...new Set(a)].sort((x, y) => x - y);
for (const v of unique) {
if (v > 0) {
if (min !== v) {
break;
}
min++;
}
}
return min;
}
This records the positive numbers that exist, then returns the smallest positive value that is still missing.