#K75567. Largest Element Appearing At Least Twice
Largest Element Appearing At Least Twice
Largest Element Appearing At Least Twice
You are given an array (a) of (n) integers. Your task is to find and print the largest element that appears at least twice. If no element appears at least twice, print (-1).
For example, if (a = [2, 3, 4, 5, 4, 5, 5]), the answer is (5) because 5 is the largest element with a frequency of at least 2.
inputFormat
The input is given from standard input (stdin) and has the following format:
- The first line contains an integer (T), the number of test cases.
- For each test case:
- The first line contains an integer (n), the size of the array.
- The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single line containing the largest element that appears at least twice in the array. If no such element exists, output (-1).## sample
5
1
1
3
2 2 2
7
2 3 4 5 4 5 5
8
1 4 3 4 3 2 2 1
5
1 5 2 4 3
-1
2
5
4
-1
</p>