← All problems

First Missing Positive

Hard arrayscyclic-sort LeetCode ↗
Find the smallest missing positive integer in an unsorted array. O(n) time, O(1) space.

Hints (0/3 revealed)

Log in to reveal hints progressively.

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.