Code Room
CodingEasycod-g1383
Subject StringsLevel Entry–Mid~12 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.