Search⌘ K
AI Features

Solution: Wildcard Matching

Explore the wildcard matching problem where you implement a pattern match supporting '?' and '*' characters. Learn how to apply a greedy algorithm to scan input and pattern strings, handle mismatches with backtracking on '*', and ensure complete string coverage. This lesson helps you understand and solve wildcard pattern matching with optimal time and space complexity.

Statement

Given an input string, s, and a pattern string, p, implement wildcard pattern matching that determines if the pattern matches the entire input string.

The pattern supports two special wildcard characters:

  • '?': Matches exactly one arbitrary character.

  • '*': Matches any sequence of characters (including zero characters).

The match must be complete, meaning the pattern should cover the entire input string, not just a part of it.

Return TRUE if the pattern matches the whole string; otherwise, return FALSE.

Constraints:

  • 00 \leq s.length ,, ...