I'm not sure this saves any time. I didn't follow the algorithm, but if I understand the problem correctly, you still need to check $array[0] through $array[$n] regardless, if you're going to declare $n+1 as a first missing number. So why probe anything beyond that?