#C8097. Majority Element Finder
Majority Element Finder
Majority Element Finder
Given an array of integers, determine if there is a majority element in the array. A majority element is defined as an element that appears more than \(\frac{n}{2}\) times, where \(n\) is the size of the array. If such an element exists, output it; otherwise, output -1.
Example:
Input: 5 1 2 3 2 2</p>Output: 2
Input: 4 1 2 3 4
Output: -1
Note: The input is provided through standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The first line of the input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single integer representing the majority element if it exists. Otherwise, print -1.
## sample5
1 2 3 2 2
2
</p>