First Missing Positive

Given an unsorted array of integers, find the smallest missing positive integer in O(n) time using cyclic sort idea.

Input Format

nums = array of integers

Output Format

The smallest missing positive integer

Constraints

  • 0 <= nums[i] <= 10^6; 1 <= nums.length <= 10^5

Examples

Example 1:

Input:

nums = [1,2,0]

Output:

3

Explanation:

1 and 2 are present, so 3 is missing.

Loading...
First Missing Positive - Arrays DSA Problem