Regular Expression Matching

00:00
HardDynamic ProgrammingStringBacktracking
GoogleFacebook

Implement regex matching with '.' (matches any single char) and '*' (matches zero or more of the preceding element).

Examples

Input → s='aa', p='a*'
Output → True
Note: a* matches 'aa'
Input → s='ab', p='.*'
Output → True
Note: .* matches anything
Input → s='aab', p='c*a*b'
Output → True
Note: c*=empty, a*='aa', b='b'