hard2-D Dynamic ProgrammingGoogleFacebook
Pattern Shell Validator
A mini-regex engine supports '.' (any char) and '*' (zero or more of the previous char) and must match the whole input.
Given a string s and pattern p with '.' and '*', return true iff p fully matches s.
Choose approach
T
F
T
F
T
F
?
F
F
T
T
F
row
?
?
?
?
?
?
?
?
?
?
?
?
1/4
Narrationstep 1 of 4
Row 1 filled (s[0..0] = "a").
Variables
i=1
How to think about it
- Row 0 handles leading x*y*z* patterns.
- Full match is dp[m][n].
Edge cases to catch in interview
- Empty pattern -> only matches empty.
- Pattern "a*" matches "" and "aaa".
Examples
Example 1
true{"s":"ab","p":".*"}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed