Search⌘ K
AI Features

Solution: Wildcard Matching

Understand how to solve wildcard matching problems by using a greedy approach that efficiently matches entire strings to patterns with '?' and '*'. Learn the step-by-step algorithm to handle matching and backtracking, and analyze time and space complexity for optimal coding interviews.

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.

...