Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Find the Index of the First Occurrence in a String
Bookmark
Brute Force
Rabin-Karp
KMP
Input
Found (start)
Not found
KMP fallback
Partial match
Custom
haystack
=
sadbutsad
,
needle
=
sad
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
needle:
s
a
d
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
needle:
s
a
d
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
j
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
j
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
j
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
j
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
algo
master
.
io
Step:
Start: find "sad" in "sadbutsad"
0 / 6
Input
Found (start)
Not found
KMP fallback
Partial match
Custom
haystack
=
sadbutsad
,
needle
=
sad
0 / 6
algo
master
.
io
Step:
Start: find "sad" in "sadbutsad"