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
Returns (boolean) false

Example 2

Input
s (string) = aa
p (string) = *
Returns (boolean) true

Example 3

Input
s (string) = cb
p (string) = ?a
Returns (boolean) false

Example 4

Input
s (string) = adceb
p (string) = *a*b
Returns (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.

Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.