Yahoo SDE Interview Question 2021 August | Advanced String Pattern Matching | Off-campus

Question · Posted Jun 2026

Question 1: Implement Z-Algorithm (String Matching) Problem Statement Given a text string and a pattern string, find all occurrences of the pattern in the text. You must implement the Z-Algorithm. The Z-Algorithm constructs a Z-array where Z[i] stores the length of the longest substring starting from i which is also a prefix of the entire string. This allows for incredibly fast O(N) pattern matching. Return a list of starting indices where the pattern occurs in the text. Constraints 1 <= ...

The full answer & interview discussion are available to premium members.

Log in Create a free account