PHP Missing Integer
function missingInteger(array $a): int
{
$min = 1;
$a = array_keys(array_flip($a));
sort($a);
foreach ($a as $v) {
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.