Search⌘ K
AI Features

Solution: Wildcard Matching

Explore how to solve the wildcard matching problem by applying greedy techniques. This lesson guides you through implementing a pattern matcher that uses '?' and '*' wildcards to match entire input strings efficiently. You will learn the pointer-based approach with backtracking to handle mismatches and understand the solution's optimal time and space complexity, strengthening your coding interview skills.

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.

...