Close
Topic list
First Missing Positive
MEDIUM
18 mins
Sorting
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Sorting
-
Arrays
-
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Binary Search
-
-
Stacks & Queues
-
Trees
-
Graph
-
Dynamic Programming
-
Greedy
-
Tries
-
Binary Search Trees
-
Heap
-
Bit Manipulation
-

First Missing Positive

Contributed by
Dhruv Sharma
Medium
Avg time to solve 18 mins
Success Rate 84 %
Share

Problem Statement

For example, the input [3, 4, -1, 1] should give output 2 because it is the smallest positive number that is missing in the input array.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
``````1
5
3 2 -6 1 0
``````
Sample Output 1:
``````4
``````
Explanation for Input 1:
``````The first positive number is 1 and it is present in the array similarly 2 and 3 are also present in the array. 4 is missing from the array. Thus, the minimum positive integer that is missing is 4.
``````
Sample Input 2 :
``````1
5
0 1 2 3 4
``````
Sample Output 2:
``````5
``````
Console