Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Find the Index of the First Occurrence in a String
Bookmark
Input
Found (start)
Not found
KMP fallback
Partial match
Custom
haystack
=
sadbutsad
,
needle
=
sad
needle:
0
s
1
a
2
d
lps:
0
0
0
needle:
0
s
1
a
2
d
lps:
0
0
0
needle:
0
s
1
a
2
d
length
i
lps:
0
0
0
needle:
0
s
1
a
2
d
length
i
lps:
0
0
0
needle:
0
s
1
a
2
d
length
lps:
0
0
0
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
lps:
0
0
0
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
lps:
0
0
0
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
lps:
0
0
0
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
i
needle:
s
a
d
lps:
0
0
0
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
needle:
s
a
d
lps:
0
0
0
haystack:
0
s
1
a
2
d
3
b
4
u
5
t
6
s
7
a
8
d
needle:
s
a
d
lps:
0
0
0
algo
master
.
io
Step:
Start: Find first occurrence of "sad" in "sadbutsad" using KMP algorithm.
0 / 9
Input
Found (start)
Not found
KMP fallback
Partial match
Custom
haystack
=
sadbutsad
,
needle
=
sad
0 / 9
algo
master
.
io
Step:
Start: Find first occurrence of "sad" in "sadbutsad" using KMP algorithm.