First Missing Positive Integer

Given an array of integers, find the smallest missing positive integer.

Statement

Given an unsorted integer array, nums, find the smallest positive integer that is missing from the array.

Implement a solution that takes O(n)O(n) time and constant space.

Examples

Let’s look at some arrays and the first missing positive integer in each:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.