← All problems
First Missing Positive
Find the smallest missing positive integer in an unsorted array. O(n) time, O(1) space.
Complexity
Time O(n), Space O(1)
Common pitfalls
- Infinite swap loops (skip when already correct)
- Forgetting numbers outside [1,n]
Your solution
Log in to save your code and track progress.