Problem 548858 · medium · Level 05 Advanced Algorithms & Graphs

Dot-Star Pattern

dynamic programming · string DP · pattern matching

A log filter uses a tiny pattern language over lowercase letters: . matches any single character and * means "zero or more copies of the element right before it" (that element is a letter or a .). A pattern must cover the entire text. Return True if text matches pattern.

Examples

Input:  text = "coolcat", pattern = "co*l.at"
Output: True
Explanation: "o*" absorbs "oo" and "." stands for "c".

Input:  text = "bee", pattern = "b.*d"
Output: False

Constraints

  • 0 <= len(text) <= 300, 0 <= len(pattern) <= 200
  • * never appears first and never follows another *.
  • Target complexity: O(len(text) * len(pattern)).

Goals

  • Treat an `x*` pair as one unit that can match zero or more characters
  • Initialise the row for the empty text so patterns like `a*b*` match nothing
Starting Python…