Skip to content
RED SAGSkills

Glob Pattern Matching

Shells and config files match file names against glob patterns. Implement matching for patterns with two special characters: ? matches exactly one character, and * matches any sequence of characters, including an empty one.

Return true if the pattern p matches the entire string s (not just part of it).

Example 1

Input: s = "adceb", p = "*a*b"
Output: true

Example 2

Input: s = "cb", p = "?a"
Output: false
Explanation: ? matches c, but a does not match b.

Constraints

  • 0 <= s.length, p.length <= 2000
  • s has lowercase letters
  • p has lowercase letters, ? and *
Hint 1

Let dp[i][j] say whether the first i characters of s match the first j of p.

Hint 2

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

Good practice for: Backend Developer, DevOps Engineer, Automation Test Engineer, Cloud Engineer, Full Stack Developer

Run checks your code on 3 sample tests. Submit runs all 10 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.