/44. Wildcard Matching

44. Wildcard Matching

Hard
Strings31.5% acceptance

Given two strings, input_string and pattern_string, determine if pattern_string matches input_string using the following rules: ? matches any single character, * matches any sequence of characters (including the empty sequence). The match must cover the entire input_string.

Example 1

Input: input_string=abcde, pattern_string=a*de

Output: True

Explanation: a*de matches abcde because * matches bc.

Example 2

Input: input_string=xyz, pattern_string=x?z

Output: True

Explanation: x?z matches xyz because ? matches y.

Example 3

Input: input_string=abcd, pattern_string=a*d?

Output: False

Explanation: a*d? does not match abcd because ? expects one more character after d.

Constraints

  • 0 <= len(input_string) <= 2000
  • 0 <= len(pattern_string) <= 2000
  • input_string consists only of lowercase English letters
  • pattern_string consists only of lowercase English letters, ? or *
Python (current runtime)

Case 1

Input: input_string='mnop', pattern_string='m*o?'

Expected: True

Case 2

Input: input_string='test', pattern_string='t*st'

Expected: True

Case 3

Input: input_string='hello', pattern_string='he*o'

Expected: True

Case 4

Input: input_string='data', pattern_string='d?t*'

Expected: True

Case 5

Input: input_string='abc', pattern_string='a*bc'

Expected: True

Case 6

Input: input_string='abc', pattern_string='a*d'

Expected: False

Case 7

Input: input_string='abcd', pattern_string='*e'

Expected: False