TypeScript Perm Missing Element
function permMissingElement(a: number[]): number {
const sorted = [...a].sort((x, y) => x - y);
for (let k = 0; k < sorted.length; k++) {
if (sorted[k] !== k + 1) {
return k + 1;
}
}
return sorted.length + 1;
}
This uses the expected sum of 1..N+1 and subtracts the actual sum to find the missing value.