Code RoomSubstring search
EasyPrep Room Coding #576

Substring search

CodingAlgorithms & data structuresEntry–Mid~12 min

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.

Implement
index_of(text: str, pattern: str) → int
Examples
in["sadbutsad","sad"]out0
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 12 min
InputExpectedGot
["sadbutsad","sad"]0not run yetsample