All problems
Wildcard Matching
Problem
Match the whole string s against the pattern p where ? matches any single character and * matches any sequence of characters including the empty one.
Use dynamic programming over prefixes: a star either consumes nothing from s or one more character from s, while a literal or question mark must consume one character from each. Return True only when the entire string matches.
Hint
Initialize the first row carefully: a pattern of stars can match the empty string.
Test cases
case 1
in: ["aa","a"]
expected: false
case 2
in: ["aa","*"]
expected: true
case 3
in: ["cb","?a"]
expected: false
case 4
in: ["adceb","*a*b"]
expected: true
case 5
in: ["","*"]
expected: true
case 6
in: ["acdcb","a*c?b"]
expected: false
Starter codePython
def wildcard_match(s, p):
# Your code here
pass6 test cases · run your code against them in the editor