#K40732. Majority Element Finder
Majority Element Finder
Majority Element Finder
You are given an integer n and a list of integers. The task is to find the majority element that appears more than \(\lfloor n/2 \rfloor\) times in the list. If no such element exists, output -1.
Note: The value n is used as the threshold parameter for counting (i.e. the majority element must occur more than \(\lfloor n/2 \rfloor\) times). The list of integers is provided in the second line and may contain a different number of elements than n.
Example:
Input: 7 3 3 4 2 4 4 2 4</p>Output: 4
inputFormat
The input consists of two lines:
- The first line contains a single integer n, which is used to compute the threshold \(\lfloor n/2 \rfloor\).
- The second line contains a space-separated list of integers.
You need to determine if there exists an element in the list that occurs more than \(\lfloor n/2 \rfloor\) times.
outputFormat
Output a single integer: the majority element if it exists; otherwise, output -1.
## sample7
3 3 4 2 4 4 2 4
4