Code Room
CodingMediumcod-g383
Subject Z algorithmLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given a text s and a pattern t (both non-empty, lowercase letters, total length <= 10^5), return the length of the longest prefix of t that appears starting at SOME position in s. Equivalently, over all start positions in s, the maximum number of leading characters of t that match. Return 0 if no character of t's prefix matches anywhere.

Implement
z_function_max_match(s: str, t: str) → int
Examples
in["xabcdez","abcx"]out3
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.