#K49007. Find the Smallest Missing Positive Integer

    ID: 28546 Type: Default 1000ms 256MiB

Find the Smallest Missing Positive Integer

Find the Smallest Missing Positive Integer

You are given an array of n integers. Your task is to find the smallest positive integer that is missing from the array.

Formally, given an array \(A\) of size \(n\), find the minimum positive integer \(x\) such that \(x > 0\) and \(x \notin A\).

Example: For \(A = [3, 4, -1, 1]\), the output should be 2, because 2 is the smallest positive number that does not occur in the array.

You are required to read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input is read from stdin and consists of two lines. The first line contains a single integer (n) which denotes the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

Output a single integer to stdout, which is the smallest positive integer that is missing from the given array.## sample

4
3 4 -1 1
2