44. Wildcard Matching
Description
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
Constraints
scould be empty or contains only lowercase lettersa-z.pcould be empty or contains only lowercase lettersa-z, and characters like?or*.
Approach
Links
Examples
Input: s = "aa", p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".
Input: s = "aa", p = "*"
Output: true
Explanation: '*' matches any sequence.
Input: s = "cb", p = "?a"
Output: false
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.
Input: s = "adceb", p = "ab"
Output: true
Explanation: The first '' matches the empty sequence, while the second '' matches the substring "dce".
Input: s = "acdcb", p = "a*c?b"
Output: false
Solutions
Follow up
Count the Number of matching characters in a pair of strings - GFG
Last updated
Was this helpful?