#K53077. Find the Dominant Integer
Find the Dominant Integer
Find the Dominant Integer
You are given an array of n integers. An integer B is said to be a dominant integer if its frequency in the array is strictly greater than the frequency of any other integer. For example, in the array [7, 1, 1, 1, 2, 3]
, the number 1
appears 3 times while all others appear once; hence, 1
is the dominant integer. If no such integer exists, output -1
.
Note: In mathematical terms, if the frequency of an integer B is \( f(B) \), then B is dominant if \( f(B) > f(x) \) for all other \( x \) in the array.
Your task is to process multiple test cases.
inputFormat
The first line contains an integer \(T\) denoting the number of test cases. For each test case, the first line contains an integer \(N\) which is the number of elements in the array. The second line contains \(N\) integers separated by spaces.
Example:
3 5 3 3 4 2 4 6 7 1 1 1 2 3 4 5 5 5 5
outputFormat
For each test case, output a single line containing the dominant integer if it exists; otherwise, output \(-1\).
Example:
-1 1 5## sample
3
5
3 3 4 2 4
6
7 1 1 1 2 3
4
5 5 5 5
-1
1
5
</p>