Problem 512779 · hard · Phase 05 Advanced Algorithms & Graphs

Filename Wildcards

dynamic programming · string DP · pattern matching

A file browser filters names with a pattern where ? matches exactly one character and * matches any sequence of characters (including the empty one). Every other character matches only itself. The pattern must match the whole name. Return True if name matches pattern.

Examples

Input:  name = "report_v2.txt", pattern = "rep*.t?t"
Output: True

Input:  name = "data.csv", pattern = "*.txt"
Output: False

Constraints

  • 0 <= len(name), len(pattern) <= 300
  • name contains letters, digits, . and _; pattern may also contain ? and *.
  • Naive backtracking over stars can take exponential time; aim for O(len(name) * len(pattern)).

Goals

  • Build a boolean table matching prefixes of a name and a pattern
  • Let a star absorb zero or more characters through two table neighbours
Starting Python…