Magic Dictionary

hard

Implement buildDict + search allowing one character mismatch

Magic Dictionary

Key Insight

While scanning searchWord, allow exactly one changed character in the trie path.

Step 1Build Dictionary
Array
HashMap
hello:1
hallo:1
leetcode:1

Store hello, hallo, leetcode as words.

1 / 3

Learn the Pattern

Practice the Code

Step-by-Step Walkthrough: Magic Dictionary

While scanning searchWord, allow exactly one changed character in the trie path.

  1. Build Dictionary

    Store hello, hallo, leetcode as words.

  2. Search with One Mismatch

    hhllo: first mismatch used at index 1, then exact match continues.

  3. Reject Exact Match as-is

    search("hello") requires one mismatch, exact path alone is not accepted.