Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Find All Anagrams in a String
Bookmark
Brute Force
Frequency Map
Match Count
Input
Example 1
Example 2
Repeating
Custom
s
=
cbaebabacd
,
p
=
abc
p
a
b
c
result =
[]
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
two strings are anagrams when their sorted forms match
p
a
b
c
result =
[]
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
two strings are anagrams when their sorted forms match
p
a
b
c
result =
[]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
sorted window
a
b
c
sorted p
a
b
c
sorted(window) =
"abc"
p
a
b
c
result =
[0]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
sorted window
a
b
e
sorted p
a
b
c
sorted(window) =
"abe"
p
a
b
c
result =
[0]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
sorted window
a
b
e
sorted p
a
b
c
sorted(window) =
"abe"
p
a
b
c
result =
[0]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
sorted window
a
b
e
sorted p
a
b
c
sorted(window) =
"abe"
p
a
b
c
result =
[0]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
window [4..6] =
"bab"
p
a
b
c
result =
[0]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
window [5..7] =
"aba"
p
a
b
c
result =
[0]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
window [6..8] =
"bac"
p
a
b
c
result =
[0, 6]
window
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
window [7..9] =
"acd"
p
a
b
c
result =
[0, 6]
c
b
a
e
b
a
b
a
c
d
0
1
2
3
4
5
6
7
8
9
result = [0, 6]
algo
master
.
io
Step:
Start: sort each window of s and compare it with sorted p
0 / 26
Input
Example 1
Example 2
Repeating
Custom
s
=
cbaebabacd
,
p
=
abc
0 / 26
algo
master
.
io
Step:
Start: sort each window of s and compare it with sorted p