Wildcard Matching - Problem
Given an input string s and a pattern p, implement wildcard pattern matching with support for '?' and '*':
'?'Matches any single character'*'Matches any sequence of characters (including the empty sequence)
The matching should cover the entire input string (not partial). Return true if the pattern matches the string, false otherwise.
Input & Output
Example 1 — Basic Wildcard Match
$
Input:
s = "abc", p = "a*c"
›
Output:
true
💡 Note:
Pattern 'a*c' matches 'abc': 'a' matches 'a', '*' matches 'b', 'c' matches 'c'
Example 2 — No Match
$
Input:
s = "abc", p = "a*d"
›
Output:
false
💡 Note:
Pattern 'a*d' cannot match 'abc': 'a' matches 'a', '*' can match 'b', but 'd' cannot match 'c'
Example 3 — Question Mark Wildcard
$
Input:
s = "abc", p = "a?c"
›
Output:
true
💡 Note:
Pattern 'a?c' matches 'abc': 'a' matches 'a', '?' matches 'b', 'c' matches 'c'
Constraints
- 0 ≤ s.length, p.length ≤ 2000
- s contains only lowercase English letters
- p contains only lowercase English letters, '?' or '*'
Visualization
Tap to expand
Understanding the Visualization
1
Input
String 'abc' and pattern 'a*c' with wildcards
2
Process
Match character by character, handling wildcards
3
Output
True if entire string matches pattern
Key Takeaway
🎯 Key Insight: Use DP to break the problem into subproblems: does pattern[0:j] match string[0:i]?
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code