Wildcard Matching

Given an input string s and a pattern p, implement wildcard pattern matching with support for two special wildcard characters:

  • ? matches exactly one arbitrary character.
  • * matches any sequence of characters, including the empty sequence.

Return true if the pattern p matches the entire string s; otherwise, return false.

The matching must cover the entire input string, not just a substring.

Example 1
Inputs = "aa", p = "a"
Outputfalse
The pattern a matches only a single a, so it cannot match the entire string aa.
Example 2
Inputs = "aa", p = "*"
Outputtrue
The * wildcard can match the entire string aa.

Constraints

  • 0 <= s.length, p.length <= 2000
  • s contains only lowercase English letters
  • p contains only lowercase English letters, '?' or '*'

Asked at 18 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate