Magic Dictionary

Build a dictionary that can answer whether a query word can match any stored word after changing exactly one character. Pattern focus: Wildcard Search with Trie (Add and Search Words). A trie-backed DFS can test one-character substitutions efficiently.

Input Format

dictionary = stored words, queries = lookup words

Output Format

boolean results for each query

Constraints

  • 1 <= dictionary.length <= 10^4
  • 1 <= queries.length <= 10^4
  • Words contain only lowercase English letters.

Examples

Example 1:

Input:

dictionary = ["hello","leetcode"]
queries = ["hello","hhllo","hell","leetcoded"]

Output:

[false,true,false,false]

Explanation:

Only hhllo differs from hello by exactly one character.

Example 2:

Input:

dictionary = ["magic","trie"]
queries = ["magix","magic","tries"]

Output:

[true,false,false]

Explanation:

Exact matches are not enough; one character must change.

Example 3:

Input:

dictionary = ["a","b"]
queries = ["c","a"]

Output:

[true,true]

Explanation:

A single-character substitution is enough to match either stored word.

Loading...
Magic Dictionary - Trie DSA Problem