First Missing Positive

Hard

Company Tags

You are given an unsorted integer array nums. Return the smallest positive integer that is not present in nums.

You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.

Example 1:

Input: nums = [-2,-1,0]

Output: 1

Example 2:

Input: nums = [1,2,4]

Output: 3

Example 3:

Input: nums = [1,2,4,5,6,3,1]

Output: 7

Constraints:

  • 1 <= nums.length <= 100,000
  • -(2^31) <= nums[i] <= ((2^31)-1)


Company Tags

Please upgrade to NeetCode Pro to view company tags.

nums =