37. Majority Element
EasyArrayBoyer-Moore Voting
The array has an element that appears more than n/2 times. Print it.
Input format
Line 1: n Line 2: n integers
Output format
The majority element.
Example 1
Input
3 3 2 3
Output
3
Example 2
Input
7 2 2 1 1 1 2 2
Output
2
Constraints
1 ≤ n ≤ 5 × 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…