Google | Phone screen | Design a dictionary with at most 1 typo
Anonymous User
5178

https://leetcode.com/problems/implement-magic-dictionary/

Design a vocabulary class that allows for a maximum of one typo. It has one method: given a word, it verifies if the word can be found in the vocabulary with at most one character substitution.

Example : Vocalubary : ['apple', 'banana', 'orange']

atMostOneTypo("banana") -> should return true
atMostOneTypo("banena") -> should return true
atMostOneTypo("banan") -> should return false
atMostOneTypo("banxnn") -> should return false

I used a trie to solve for the question, that would fail one edge case where the typo is at beginning of input. Wrote pseudocode and explained how I would overcome that issue.
Also dicussed on how to use HashMap for solving the question.

Comments (14)