#K77162. Second Smallest Unique Integer
Second Smallest Unique Integer
Second Smallest Unique Integer
You are given several test cases. In each test case, a sequence of integers is provided on a single line separated by spaces. The task is to determine the second smallest unique integer in the sequence. If the sequence contains fewer than two unique integers, output -1
.
Problem Details:
- For each test case, remove duplicate integers and sort the remaining unique values in increasing order.
- If there are at least two unique numbers, return the second smallest number; otherwise, return
-1
.
The input begins with an integer T indicating the number of test cases, followed by T lines each representing a test case. The expected output is the result for each test case printed on a new line.
For mathematical notation in LaTeX, let \( S \) be the set of unique integers extracted from the list. If \( |S| \ge 2 \), then the answer is the second smallest element in \( S \); otherwise, the answer is \( -1 \).
inputFormat
The input is read from standard input (stdin) and has the following format:
T line_1 line_2 ... line_T
Where:
T
is a positive integer representing the number of test cases.- Each
line_i
contains a sequence of space-separated integers representing a single test case.
outputFormat
For each test case, output the second smallest unique integer on a separate line. If there are fewer than two unique integers in the test case, output -1
.
The output is written to standard output (stdout) with each answer on a new line.
## sample4
1 3 4 2 1 2
5 5 5 5
2 1
10
2
-1
2
-1
</p>