Regular Expression Matching - Problem
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
'.'matches any single character'*'matches zero or more of the preceding element
The matching should cover the entire input string (not partial).
Input & Output
Example 1 — Basic Star Pattern
$
Input:
s = "aa", p = "a*"
›
Output:
true
💡 Note:
The pattern 'a*' means zero or more 'a' characters. Since the string contains exactly two 'a's, the pattern matches.
Example 2 — Dot Wildcard
$
Input:
s = "ab", p = ".*"
›
Output:
true
💡 Note:
The pattern '.*' means zero or more of any character. This can match any string, including 'ab'.
Example 3 — No Match
$
Input:
s = "mississippi", p = "mis*is*p*."
›
Output:
false
💡 Note:
The pattern expects one more character at the end (the '.'), but the string ends after 'i'.
Constraints
- 1 ≤ s.length ≤ 20
- 1 ≤ p.length ≤ 30
- s contains only lowercase English letters
- p contains only lowercase English letters, '.', and '*'
- '*' always appears after a preceding element
Visualization
Tap to expand
Understanding the Visualization
1
Input
String s="aa" and pattern p="a*"
2
Process
Check if pattern can match entire string
3
Output
Return true if complete match found
Key Takeaway
🎯 Key Insight: Use dynamic programming to handle overlapping subproblems when matching patterns with wildcards
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code