Implement Magic Dictionary

Medium · Trie · about 20 minutes

Asked at Google, Amazon, Microsoft.

Design a dictionary that answers whether a word can match a stored word by changing exactly one character.

  • MagicDictionary() creates it.
  • buildDict(dictionary) stores a list of distinct words.
  • search(searchWord) returns true if changing exactly one character of searchWord gives a stored word.

Related guides