Arrays & HashingHard

First Missing Positive

Return the smallest positive whole number that is not in nums. Aim for O(n) time and O(1) extra space.

Example 1nums = [5, 2, -3, 1, 9] → 3
Example 2nums = [1, 2, 3] → 4
1 ≤ n ≤ 10⁵ · −2³¹ ≤ nums[i] < 2³¹

Hints

0 of 3 open
Hint 2 · the patternHint 3 · the key line