Linear-time string search: Return the first index where pattern occurs in text, or -1 when it does not occur. Use prefix reuse so worst-case time is linear in text plus pattern length.
Input: A JSON object { "text": string, "pattern": string }.
Output: A JSON integer.
Constraints:
- 0 <= text.length,pattern.length <= 100000
- An empty pattern matches at index 0
- Compare characters case-sensitively
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: EASY. Variant: 4. Balance correctness, maintainability, and clear review-ready code.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked easy difficulty.
The signed-in workspace provides the tools required by the round, such as recording, co