Implement the method isWildcardMatch that checks whether a string matches a wildcard pattern.

The pattern supports ? for exactly one character and * for any sequence of characters, including empty.

The task is designed to test careful handling of edge cases, not only the most common input.

  • The entire string must match the entire pattern.
  • Normal letters must match exactly.
  • * can either match nothing or consume one more character.
Example 1
Input:
s (string) = aa
p (string) = a
Return:
(boolean) false
Example 2
Input:
s (string) = aa
p (string) = *
Return:
(boolean) true
Example 3
Input:
s (string) = cb
p (string) = ?a
Return:
(boolean) false
Example 4
Input:
s (string) = adceb
p (string) = *a*b
Return:
(boolean) true

Use dynamic programming where dp[i][j] means the first i characters of the string match the first j characters of the pattern.

Run your code to see the result.