easy +10 pts

Wildcard Match (Simple)

Implement a simple wildcard matcher supporting '*' for any sequence and '?' for a single character.

Write a function `wildcard_match(pattern: str, text: str) -> bool` that returns `True` if `text` matches `pattern` using the following rules: - `'?'` matches exactly one character. - `'*'` matches any sequence of characters, including the empty sequence. - All other characters match themselves exactly. The match must cover the entire string (not just a substring). You may assume both inputs are non-empty and contain only lowercase letters and the wildcard characters `'?'` and `'*'`. Solve it without using regular expressions or the `fnmatch` module.

Constraints

Input lengths: 1 ≤ len(pattern) ≤ 10, 1 ≤ len(text) ≤ 10. The function should be efficient enough for these small sizes; recursive backtracking is acceptable.

Example

>>> wildcard_match("a?c", "abc")
True
>>> wildcard_match("a*c", "abc")
True
>>> wildcard_match("a*c", "ac")
True
>>> wildcard_match("a*c", "ab")
False
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use recursion with two indices: one for pattern, one for text.
If pattern[i] is '*', try matching zero or more characters.
If pattern[i] is '?', it must match exactly one character.
When the pattern is exhausted, the text must also be exhausted.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.