Problems > Wildcard Matching

Wildcard Matching

Difficulty: 2000 5000 ms 128 MB

strings dp

Does pattern P match text T entirely? In P, ? matches any single character and * matches any (possibly empty) run of characters.

Input: the first line has T; the second line has P.

Output: YES if P matches all of T, else NO.

Constraints:

  • 1 ≤ |T|, |P| ≤ 2000
  • T is lowercase; P has lowercase, ? and *

Sample Tests

Input 1
abcd
a*d
Output 1
YES
Input 2
ab
a?c
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.