Skip to content
BytePatterns

Wildcard Word Search

MediumTries#trie#backtracking~30m

Problem

Build a dictionary from a list of words, then answer search queries where a . in the query matches any single character. A query matches only if some stored word has exactly the same length and agrees on every non-dot position.

Examples

Input:  words = ["bad", "dad", "mad"], query = ".ad"
Output: True
Why:    the dot can stand for b, d or m
Input:  words = ["bad", "dad", "mad"], query = "pad"
Output: False
Why:    no stored word starts with p
Input:  words = ["bad"], query = "ba"
Output: False
Why:    edge case, a prefix is not a stored word

Hints

0 / 3

Stuck on the idea rather than the code? Trie Basics covers it.