789. Wildcard Pattern Matching (? and *)

MediumRecursionRecursion

Given a string s and a pattern p containing '?' (matches any single char) and '*' (matches any sequence of chars including empty), return true if p matches the entire string s, else false. Implement with recursion + memoization. Input: two quoted strings separated by comma.

Input: Two strings: "s", "p".

Output: Return a boolean: true or false.

Examples

Example 1
Input: "aa", "*"
Output: true
Explanation: * matches any sequence.
Example 2
Input: "cb", "?a"
Output: false
Explanation: ? matches c but a != b.
Example 3
Input: "adceb", "*a*b"
Output: true
Explanation: * matches '', a matches a, * matches 'dce', b matches b.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →