#C9563. Smallest Missing Positive Integer

    ID: 53670 Type: Default 1000ms 256MiB

Smallest Missing Positive Integer

Smallest Missing Positive Integer

Given an array of integers, your task is to find the smallest positive integer that is not present in the array. For instance, if the array contains [1, 2, 0], the smallest missing positive integer is 3. This problem requires careful consideration of edge cases including duplicate values, negative integers, and unsorted input. Mathematically, if we denote the set of integers in the array as \(S\), we need to find the minimum \(x \in \mathbb{N}\) such that \(x \notin S\).

inputFormat

The input is provided via standard input and begins with an integer \(T\), representing the number of test cases. Each test case consists of two lines. The first line contains an integer \(N\), the number of elements in the array. The second line contains \(N\) space-separated integers.

Example:

4
3
1 2 0
4
3 4 -1 1
5
7 8 9 11 12
1
1

outputFormat

For each test case, output the smallest missing positive integer on a separate line via standard output.

Example Output:

3
2
1
2
## sample
1
3
1 2 0
3

</p>