2-D Dynamic Programming Two strings
564. Wildcard Matching
You are given a string s and a pattern p. Return true if the pattern matches the whole of s, and
false otherwise.
The pattern is made of lowercase letters and two wildcards:
- A letter matches that same letter.
?matches exactly one character, whatever it is.*matches any run of characters, including the empty run.
The match has to cover s from its first character to its last. Matching only part of s is not enough.
Example 1
Input: s = "sunflower", p = "s*f?ow*"
trueExplanation: The first * matches "un", the ? matches l, and the last * matches "er". The letters s,
f, o and w match themselves.
Example 2
Input: s = "", p = "**"
trueExplanation: Each * matches the empty run, so the pattern matches the empty string.
Example 3
Input: s = "cabin", p = "*b?"
falseExplanation: The pattern's b can only be the b in s. Then the ? matches i, and the n is left over, so
the pattern does not cover all of s.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
0 ≤ s.length, p.length ≤ 3000sholds only lowercase English letters.pholds only lowercase English letters,?and*.
Clarifying questions
What you would ask an interviewer before writing any code.