Step-by-step DP table filling animation
. โ Matches any single character.
Example: a.c โ "abc", "axc", "a1c" matches
* โ Repeats the preceding element zero or more times.
Example: a* โ "", "a", "aa", "aaa", ... matches
Example: .* โ har qanday qatormatches (universal)
If p[j-1] == '*':
1. Zero times: dp[i][j] = dp[i][j-2]
โ We completely skip the "x*" pair
2. One+ times: If s[i-1] == p[j-2] or p[j-2] == '.'
dp[i][j] = dp[i][j] || dp[i-1][j]
โ We "consume" one character from s, pattern stays
If s[i-1] == p[j-1] or p[j-1] == '.':
dp[i][j] = dp[i-1][j-1]
โ Characters match โ take the diagonal value
Otherwise:
dp[i][j] = false
โ Characters do not match