Code RoomLongest prefix match in text
MediumPrep Room Coding #952

Longest prefix match in text

CodingAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
["xabcdez","abcx"]3not run yetsample