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
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.