Skip to content
Onsite

Wildcard Matching

HardP3Coding

Implement wildcard matching of the whole string s against the pattern p, where p may contain:

  • ? which matches any single character,
  • * which matches any sequence of characters, including the empty sequence.

Return true only if the pattern covers the entire string.

Example 1

Input
s = "aa", p = "a"
Output
false
Why
A single `a` cannot cover two characters.

Example 2

Input
s = "aa", p = "*"
Output
true
Why
`*` matches any string.

Example 3

Input
s = "cb", p = "?a"
Output
false

Constraints

  • 0 <= s.length, p.length <= 1000
  • s contains lowercase letters; p contains lowercase letters, ? and *

Hints

Run checks the 3 visible tests, Submit all 13.