#K4421. Smallest Missing Positive Integer
Smallest Missing Positive Integer
Smallest Missing Positive Integer
You are given T test cases. In each test case, you are provided with an integer N representing the size of the array, followed by N integers. Your task is to find the smallest missing positive integer for each test case.
For a given array A, you need to determine the smallest positive integer x such that x ∉ A. Mathematically, if we denote the set of elements in the array by \( A \), then you must find the smallest integer \( x \in \mathbb{Z}^+ \) satisfying:
[ x \notin A ]
For example, if the array is [1, 2, 0], the smallest missing positive integer is 3. If the array is [3, 4, -1, 1], then the answer is 2.
Please note that the input and output should be handled via standard input (stdin) and standard output (stdout) respectively.
inputFormat
The input is given via standard input (stdin) and has the following format:
The first line contains an integer T, representing the number of test cases. Each test case contains two lines:
- The first line of a test case contains an integer N, indicating the number of elements in the array.
- The second line contains N space-separated integers, which are the elements of the array.
For example:
3 3 1 2 0 5 3 4 -1 1 1 -1
outputFormat
For each test case, output a single line containing the smallest missing positive integer. The answers for each test case should be printed in the same order as the input test cases.## sample
3
3
1 2 0
5
3 4 -1 1
1
-1
3
2
1
</p>