#C2008. Second Largest Unique Element

    ID: 45277 Type: Default 1000ms 256MiB

Second Largest Unique Element

Second Largest Unique Element

Given an array of integers, your task is to find the second largest unique element in the array. If there is no such element (i.e. there are fewer than two distinct numbers), output -1.

For example, given the array [1, 2, 3, 4, 5], the largest unique element is 5 and the second largest unique element is 4. In the array [7, 7, 7, 7], since there is only one unique element, the output should be -1.

inputFormat

The input begins with a single integer T representing the number of test cases. Each test case starts with an integer n denoting the number of elements in the array, followed by n space-separated integers on the next line. All input is provided via standard input (stdin).

Example: 3 5 1 2 3 4 5 4 7 7 7 7 7 9 8 7 7 6 6 5

outputFormat

For each test case, output a single line containing the second largest unique element of the array. If such an element does not exist, output -1. The output should be printed to standard output (stdout).

Example: 4 -1 8 ## sample

3
5
1 2 3 4 5
4
7 7 7 7
7
9 8 7 7 6 6 5
4

-1 8

</p>