Implement Magic Dictionary
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement MagicDictionary, which answers the question: "can I turn this word into a dictionary word by changing **exactly one** letter?"
- MagicDictionary() creates an empty structure.
- buildDict(dictionary) loads a list of distinct words. It is called exactly once, before any search.
- search(searchWord) returns true if replacing exactly one character of searchWord with a *different* character produces a word in the dictionary, and false otherwise.
A word that is already in the dictionary does not match itself (zero changes), but it can still return true if some other dictionary word is one letter away.
Examples
Constraints
- 1 <= dictionary.length <= 100
- 1 <= dictionary[i].length, searchWord.length <= 100
- Words consist of lowercase English letters; `dictionary` words are distinct
- `buildDict` is called once before any `search`
- At most 100 calls to `search`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.