15% off all plans & roadmaps Use code
See plansSolution & editorial
Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
Longest Word in Dictionary is a Design Patterns problem, in the Tries subpattern. The pattern covers tries, LRU/LFU cache, and data structure design
Implement Trie data structure for prefix-based operations and autocomplete systems.
The reference solution runs in O(n) time and O(t) space.
Longest Word in Dictionary has been reported in interviews at Goldman Sachs, Facebook.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Longest Word in Dictionary is a Design Patterns problem, in the Tries subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.