1170. Wildcard Matching (? and *)

EasyDynamic ProgrammingSequence DP

Given a string s and a pattern p containing lowercase letters, '?' (matches any single character), and '*' (matches any sequence including empty), determine whether p matches the entire string s. Return true or false. The input is JSON {s, p}.

Input: JSON {s, p}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"s":"aa","p":"*"}
Output: true
Explanation: '*' matches everything.
Example 2
Input: {"s":"cb","p":"?a"}
Output: false
Explanation: 'a' does not match 'b'.
Example 3
Input: {"s":"adceb","p":"*a*b"}
Output: true
Explanation: Stars absorb the gaps.

Constraints

Asked by

BloombergMicrosoftGoogleInfosysAmazonMeta
Solve this problem in the editor →