Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Smallest Missing Positive Number

XPChallenge Points: 30
levelLevel: Hard

You are given an unsorted list of integers. Your task is to find the smallest positive number that is not in the list.
You should solve this in linear time O(n) and constant extra space O(1).

Example 1:

Input: nums = [2,3,1]

Output: 4

Explanation:

Numbers 1, 2, 3 are present, so the smallest missing positive is 4.

Example 2:

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

Output: 3

Explanation:

1, 2, 4, 5 are present, but 3 is missing.

Example 3:

Input: nums = [7,8,9]

Output: 1

Explanation:

1 is the smallest positive number and it is missing.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result