Why it matters

Wildcard matching is common variant. Understanding shapes string DP.

Advertisement

The architecture

dp[i][j] = match s[0..i], p[0..j].

* handles two cases: match zero or more.

Wildcard DPMatch ? or literaldp[i-1][j-1]*: match zerodp[i][j-1]*: match one+dp[i-1][j]Regex ('.' + '*') has similar structure but more nuanced due to preceding char
Wildcard match.
Advertisement

How it works end to end

? matches one char.

* matches zero or more.

Space O(m) with rolling.

Recursive with memo works too.