Substring search

Write codeEasy12 min

Your task

Implement substring search by hand. Given a text and a pattern, return the index of the first occurrence of the pattern in the text, or -1 if it never occurs. An empty pattern matches at index 0. Use a direct character-by-character scan, no regex and no built-in search helpers. For example, the pattern 'sad' first occurs in 'sadbutsad' at index 0.

Examples

index_of(text: str, pattern: str) -> int
Example 1
Inputindex_of("sadbutsad", "sad")
Output0