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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input: text
s, patternpwith letters, '.', and ''; every '' follows a valid element. - Output: true only if the entire
smatches the entirep....
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...