Find the Index of the First OccurrenceEasy

two pointers string string matching

Return the index of the first occurrence of needle in haystack, or -1 if it is not present. Two approaches — slide a window, or use KMP to skip redundant work.

Press play to watch the algorithm run.
Metrics
Legend
How it works
0 / 0