Basic occurrence
Input
find_substring_index('hello', 'll')
Output
2
The substring 'll' starts at index 2 in 'hello'.
Full lesson preview
Return the first index where a substring appears in a string, or -1 if not present.
Problem statement
Task
Examples
Input
find_substring_index('hello', 'll')
Output
2
The substring 'll' starts at index 2 in 'hello'.
Input format
Output format
Constraints
Samples
Input
find_substring_index('abc', 'a')
Output
0
'a' occurs at index 0.
Input
find_substring_index('abc', 'z')
Output
-1
'z' is not present, so return -1.