#K3121. Wildcard Pattern Matching

    ID: 24889 Type: Default 1000ms 256MiB

Wildcard Pattern Matching

Wildcard Pattern Matching

You are given two strings s and p where p is a pattern that may contain wildcard characters. The wildcard characters are:

  • * which matches any sequence of characters (including the empty sequence)
  • ? which matches any single character

Your task is to determine if the entire string s matches the pattern p exactly.

The matching should cover the entire input string (not partial).

Note: Use dynamic programming or any efficient method to solve the problem as the input strings can be large.

For example, given s = "abcdef" and p = "a*d?f", the output should be True.

inputFormat

The input consists of two lines:

  1. The first line contains the string s.
  2. The second line contains the pattern p which may include the wildcards * and ?.

Both s and p consist only of printable ASCII characters.

outputFormat

Output a single line: True if string s matches pattern p according to the described rules, otherwise output False.

## sample
abcdef
a*d?f
True