Problem
Ask
Submissions

Problem: First Missing Positive

Medium
30 min
Understand how to identify and return the smallest missing positive integer from an unsorted array by applying cyclic sort. This lesson helps you develop an efficient O(n) time and constant space solution, enabling you to handle similar array-based problems in coding interviews.

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 11.

Constraints:

  • 11 \leq nums.length 105\leq 10^5

  • 231-2^{31} \leq nums[i] 2311\leq 2^{31} - 1

Problem
Ask
Submissions

Problem: First Missing Positive

Medium
30 min
Understand how to identify and return the smallest missing positive integer from an unsorted array by applying cyclic sort. This lesson helps you develop an efficient O(n) time and constant space solution, enabling you to handle similar array-based problems in coding interviews.

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 11.

Constraints:

  • 11 \leq nums.length 105\leq 10^5

  • 231-2^{31} \leq nums[i] 2311\leq 2^{31} - 1