#C6161. Second Largest Unique Value
Second Largest Unique Value
Second Largest Unique Value
You are given several test cases. For each test case, you are given an integer N followed by a list of N integers. Your task is to find the second largest unique value in the list. If the list has less than two distinct numbers, print -1
.
Let \( S \) be the set of distinct numbers in the list. The condition for a valid answer is \( |S| \ge 2 \). If \( S = \{ s_1, s_2, \ldots \} \) sorted in descending order, then your answer is \( s_2 \).
inputFormat
The first line of input contains a single integer T representing the number of test cases. For each test case:
- The first line contains an integer N, the number of elements in the list.
- The second line contains N space-separated integers.
outputFormat
For each test case, output a single line containing the second largest unique integer in the list. If no such value exists, output -1
.
1
5
4 2 1 3 2
3
</p>