Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Majority Element
Bookmark
Brute Force
Hash Map
Sorting
Boyer-Moore
Input
Example 1
Majority at Start
Majority at End
Custom
arr
=
[2, 2, 1, 1, 1, 2, 2]
2
2
1
1
1
2
2
0
1
2
3
4
5
6
candidate
count
0
need
4
2
2
1
1
1
2
2
0
1
2
3
4
5
6
candidate
count
0
need
4
2
2
1
1
1
2
2
0
1
2
3
4
5
6
candidate
2
count
0
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
1
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
2
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
2
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
2
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
3
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
4
need
4
2
2
1
1
1
2
2
j
0
1
2
3
4
5
6
candidate
2
count
4
need
4
2
2
1
1
1
2
2
0
1
2
3
4
5
6
candidate
2
count
4
need
4
algo
master
.
io
Step:
Start: a majority element must appear at least 4 times
0 / 10
Input
Example 1
Majority at Start
Majority at End
Custom
arr
=
[2, 2, 1, 1, 1, 2, 2]
0 / 10
algo
master
.
io
Step:
Start: a majority element must appear at least 4 times