60. Majority Element
Challenge1000 ms256 MBSolved by 0%
An element is a majority element if it appears strictly more than
n / 2 times.
Print that element if one exists, or None if no element appears often enough.
Note the "strictly more" — in an array of 4 elements, appearing twice is not enough.
Constraints - `1 ≤ n ≤ 200000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print the majority element, or None if no value appears strictly more than n/2 times.
Input7
3 3 4 2 3 3 3
Output3
Notehas a clear majority element
Input4
1 2 3 4
OutputNone
Notehas no repeated element at all
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution