Search⌘ K
AI Features

Problem: First Missing Positive

Explore how to identify the first missing positive integer in an unsorted array with a linear time and constant space algorithm. Learn to use the array itself as a hash map through cyclic sort to place integers in their correct positions. Understand this technique to optimize performance and solve similar array problems efficiently.

Statement

Given an unsorted integer array nums, find and return the smallest positive integer that is not present in nums.

Your solution must run in O(n)O(n) time and use O(1)O(1) auxiliary space.

Constraints:

  • 11 \leq nums.length 105\leq 10^5 ...