Given two strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Input:
hello
ll
Output: 2
Input:
aaaaa
bba
Output: -1
Input:
abc
Output: 0
Your program must print a single integer (index) so it can be compared with the expected output.
No submissions yet.
Discuss brute-force string matching vs optimized approaches like KMP.