First Missing Positive

Given an unsorted integer array, find the smallest missing positive integer. Cyclic placement is ideal because values in the range 1..n can be positioned by index.

Input Format

nums = array of integers

Output Format

smallest missing positive integer

Constraints

  • 1 <= nums.length <= 10^5; -10^9 <= nums[i] <= 10^9

Examples

Example 1:

Input:

nums = [1,2,0]

Output:

3

Explanation:

1 and 2 are present, so 3 is the first missing positive.

Example 2:

Input:

nums = [3,4,-1,1]

Output:

2

Explanation:

2 is the smallest positive missing from the array.

Loading...
First Missing Positive