Match Log Lines Against a Pattern with Dot and Star

Last updated: November 29, 2026

Quick Overview

Implement full-string matching of text s against a pattern p where '.' matches any single character and 'x*' matches zero or more copies of the preceding element x.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement full-string matching of text s against a pattern p where '.' matches any single character and 'x*' matches zero or more copies of the preceding element x.

Framed around a simplified log filter in a tool like Cloud Logging, this is a demanding DP question in the Google onsite style. The interviewer looks for a correct treatment of star as zero-or-more of the previous token, a clean table definition, and careful base cases for patterns like a*b*c* matching the empty string.

What the Interviewer Expects
  • Defines dp[i][j] as whether s[i:] matches p[j:] (or the prefix version) explicitly
  • Handles star by either skipping the pair or consuming one matching character
  • Gets the empty-string base cases right
  • Explains why greedy matching fails
  • Gives O(m * n) time and verifies on a tricky case
Key Topics to Cover
Dynamic Programming
Strings
Regular Expressions
Recursion
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Add '+' (one or more) and '?' (zero or one).
  • Support wildcard matching where '*' matches any sequence on its own (glob style).
  • How would you match one pattern against millions of log lines per second?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: text s, pattern p with letters, '.', and ''; every '' follows a valid element.
  • Output: true only if the entire s matches the entire p....
High-Level Design

Let dp[i][j] mean s[i:] matches p[j:]. Base: dp[m][n] = True. Fill from the end. At (i, j), let first = i < m and p[j] in (s[i], '.'). If the next pattern character is '*', the pair `p[j]p[j...


Submit Your Answer
Markdown supported