Learn
Practice
Newsletter
Resources
F
Toggle theme
0
F
Toggle theme
0
Toggle menu
← Back to All Animations
Mo's Algorithm
Bookmark
Input
Standard
All Distinct
All Same
Large
Custom
arr
=
[1, 3, 2, 1, 3, 2, 1]
,
queries
=
[[0,3],[1,5],[2,6],[0,6]]
Block Size = 2
Block 0
Block 1
Block 2
Block 3
1
0
3
1
2
2
1
3
3
4
2
5
1
6
Queries (sorted by Mo's order)
Q0: [0, 3]
Q1: [1, 5]
Q2: [2, 6]
Q3: [0, 6]
algo
master
.
io
Step:
Start: Mo's Algorithm — answer 4 range queries on array of size 7. Block size = floor(sqrt(7)) = 2.
0 / 23
Input
Standard
All Distinct
All Same
Large
Custom
arr
=
[1, 3, 2, 1, 3, 2, 1]
,
queries
=
[[0,3],[1,5],[2,6],[0,6]]
0 / 23
Block Size = 2
Block 0
Block 1
Block 2
Block 3
1
0
3
1
2
2
1
3
3
4
2
5
1
6
Queries (sorted by Mo's order)
Q0: [0, 3]
Q1: [1, 5]
Q2: [2, 6]
Q3: [0, 6]
algo
master
.
io
Step:
Start: Mo's Algorithm — answer 4 range queries on array of size 7. Block size = floor(sqrt(7)) = 2.