InferenceAI

Enter at least two characters to search.

Start free

Wildcard Pattern Match

hardDynamic Programming40 min50 XP

Return True if the pattern p matches the whole string s, where ? matches any single character and * matches any sequence (including empty).

Examples

EXAMPLE WALKTHROUGHtoo short

A guided view of the published example, not a trace of your code.

INPUT["aa","a"]
TASKwildcard_pattern_match()
EXPECTED OUTPUTfalse

Start with the input values shown in this example.

Example 1 of 3

Input: s = "aa", p = "a"

Output: false

Explanation: too short

Input: s = "aa", p = "*"

Output: true

Explanation: star

Input: s = "cb", p = "?a"

Output: false

Explanation: mismatch

Hint 1

dp[i][j] = s[:i] matches p[:j].

Hint 2

A '*' either matches nothing (dp[i][j-1]) or one more character (dp[i-1][j]).

Topics

DSADynamic ProgrammingPython