Search⌘ K
AI Features

First Missing Positive

Explore how to identify the smallest missing positive integer from an unsorted array by applying the cyclic sort pattern. Understand the problem constraints and implement an efficient O(n) time and O(1) space algorithm, gaining practical coding skills that optimize for time and space complexity.

Statement

Given an unsorted integer array, nums, return the smallest missing positive integer. Create an algorithm that runs with an O(n)O(n) time complexity and utilizes a constant amount of space.

Note: The smallest missing positive isn’t the first positive number that’s missing in the range of elements in the input, but the first positive number that’s missing if we start from 1 ...