38. First Missing Positive

HardArray

Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.

Examples

Input: [1,2,0]

Output: 3

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

Constraints

  • 1 <= nums.length <= 10^5
  • -2^31 <= nums[i] <= 2^31 - 1
Loading...

Run checks all cases above. Submit evaluates all test cases.