Solución
solution.tsTypeScript
function findFirstMissingPositive(numbers: number[]): number {
const ns = JSON.parse(numbers as any as string)
let min = Number.MAX_SAFE_INTEGER;
let max = -Number.MAX_SAFE_INTEGER;
let count = new Set();
console.log(ns)
for (const n of ns) {
if (n > 0) {
max = Math.max(max, n);
min = Math.min(min, n);
count.add(n)
}
}
if (min === Number.MAX_SAFE_INTEGER) return 1
let i = 1;
while (i < max) {
if (!count.has(i)) return i;
i++
}
if (i === count.size) return i + 1
return i;
}
// No modificar: necesario para evaluar el resultado.
export { findFirstMissingPositive };0respuestas