#K80252. Smallest Missing Positive Integer

    ID: 35489 Type: Default 1000ms 256MiB

Smallest Missing Positive Integer

Smallest Missing Positive Integer

You are given an unsorted integer array. Your task is to find the smallest missing positive integer from the array.

The problem requires you to ignore negative numbers, zero, and duplicate positive values. The solution should efficiently handle large inputs.

Formally, given an array \(A\) of \(n\) integers, find the smallest positive integer \(m\) such that \(m \notin A\). For example, if \(A = [3, 4, -1, 1, 2]\), then the answer is \(5\), as integers \(1\) through \(4\) are present in the array.

Note that the answer should be computed in an efficient manner.

inputFormat

The first line contains an integer (n), denoting the number of elements. The second line contains (n) space-separated integers.

outputFormat

Output the smallest positive integer that does not appear in the input array.## sample

3
1 2 0
3