#C13434. Find the Missing Positive Integer
Find the Missing Positive Integer
Find the Missing Positive Integer
Given an unsorted list of integers, your task is to find the smallest positive integer (greater than 0) that is missing from the list.
Note: The solution should work efficiently in O(n) time with constant extra space. The input will be read from stdin
and the output should be printed to stdout
.
Example: For the input 3 4 -1 1
(with array size provided), the missing positive integer is 2
, since 1 is present and 2 is the smallest number greater than 0 that is absent.
inputFormat
The first line of input contains a single integer n that denotes the size of the array. If n is 0, the array is empty. The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single integer representing the smallest missing positive integer.
## sample4
3 4 -1 1
2
</p>