#C1793. Smallest Missing Positive Integer
Smallest Missing Positive Integer
Smallest Missing Positive Integer
You are given an array of integers. Your task is to find the smallest positive integer, i.e. an integer greater than 0, that does not appear in the array. Formally, if the array is denoted by \( A \), you need to find the smallest \( x \in \mathbb{N^+} \) such that \( x \notin A \).
For example, if the input array is [3, 4, -1, 1, -2, 2]
, the answer is 5
because integers 1, 2, 3, and 4 are present in the array and 5 is the smallest missing positive integer.
This problem requires you to efficiently determine the missing number even when the list contains negative numbers or duplicates.
inputFormat
The input is given via standard input (stdin). The first line contains a single integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers representing the array elements.
For example:
6 3 4 -1 1 -2 2
outputFormat
Output a single integer representing the smallest positive integer that is missing from the array. The output should be written to standard output (stdout).
For example, for the above input, the output should be:
5## sample
6
3 4 -1 1 -2 2
5