Back to course home
0% completed
Vote For New Content
First Missing Positive (hard)
Problem Statement
Given an unsorted array nums
containing positive and negative integers, return the smallest
missing
positive integer value.
Note: You must implement algorithm in o(n) time and uses o(1) space.
Examples
-
Example 1:
- Input: [5, 3, -1, 8, 4, 2]
- Expected Output: 1
- Justification: The first missing positive integer in the array is 1.
-
Example 2:
- Input: [2, 5, -7, 3, 9, 4, 6, 1]
- Expected Output: 7
- Justification: The array contains all integers from 1 to 6, so the first missing positive integer is 7.
-
Example 3:
- Input: [-4, -3, -2, -1]
- Expected Output: 1
- Justification: Since there are no positive integers, the first missing positive integer is 1.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible