Determine whether a pattern containing ? and * can match an entire input string.
Problem
You are given two strings:
s: the input textp: a pattern that may contain ordinary lowercase characters plus two wildcard symbols:?matches exactly one character*matches any sequence of characters, including the empty sequence
Return whether the entire string s can be matched by the entire pattern p.
A match must consume all characters in both strings. Partial matches do not count.
Input Format
- A string
s - A string
p
Both strings are composed of lowercase letters and the pattern may additionally contain ? and *.
Output Format
- Return
trueifpmatches all ofs - Otherwise return
false
Constraints
- Match must cover the full string and full pattern
?matches exactly one character*matches zero or more characters- Strings are assumed to be non-empty or empty depending on the test case
Example 1
Input
s = "adceb", p = "*a*b"
Output
true
Explanation
* can match the empty prefix, then a matches a, the second * matches dce, and b matches b.
Example 2
Input
s = "acdcb", p = "a*c?b"
Output
false
Explanation
No assignment of characters to the wildcards allows the pattern to consume the entire string while preserving the fixed letters.
Show 1 more example
Example 3
Input
s = "", p = "*"
Output
true
Explanation
* can match the empty sequence.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.