41. First Missing Positive

Practice First Missing Positive for free on NudgeCode: Hard, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return the smallest positive integer (1, 2, 3, ...) that does not appear in nums. The array is unsorted. Aim for O(n) time and O(1) extra space; you may modify nums.

Example

nums = [3,4,-1,1]  ->  2

Constraints