#K4286. Smallest Missing Positive Integer

    ID: 27181 Type: Default 1000ms 256MiB

Smallest Missing Positive Integer

Smallest Missing Positive Integer

In this problem, you are given T test cases. For each test case, you are provided with an integer ( n ) followed by ( n ) integers. Your task is to determine the smallest missing positive integer greater than 0 that does not appear in the list for each test case.

The answer for each test case should be printed on a new line.

For example, given an array [1, 2, 0], the smallest missing positive integer is 3 because 1 and 2 are present. Use the following formula to describe the answer for a test case with set ( S ) of integers:

[ answer = \min{ i \in \mathbb{Z}^{+} : i \notin S } ]

Note that you should read input from standard input (stdin) and write output to standard output (stdout).

inputFormat

The input is given on standard input and consists of multiple test cases. The first line contains an integer ( T ) representing the number of test cases. For each test case:

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

For example:

1 3 1 2 0

outputFormat

For each test case, output a single line containing the smallest missing positive integer greater than 0.## sample

1
3
1 2 0
3

</p>