Simple majority
Input
majority_element([3, 3, 4])
Output
3
3 appears 2 of 3 times, which is > 3/2, so it's the majority.
Full lesson preview
Find the element that appears more than half the time using Boyer–Moore Voting Algorithm.
Problem statement
Task
Examples
Input
majority_element([3, 3, 4])
Output
3
3 appears 2 of 3 times, which is > 3/2, so it's the majority.
Input format
Output format
Constraints
Samples
Input
[2, 2, 1, 1, 2]
Output
2
2 appears 3 times out of 5, which is > 5/2.