Python Trie+DFS solution
We first insert all the words to the Trie. Then, we go through the words again and look for the longest word in the dictionary using DFS. As soon as we see that
We first insert all the words to the Trie. Then, we go through the words again and look for the longest word in the dictionary using DFS. As soon as we see that any word leading up to a word doesn\'t exist in the Trie we can stop searching deeper. Since we sort the words beforehand we have the longest word with the smallest lexicographical order. Instead of sorting we can also check upon a tie whether the new path is lexicographically smaller.\n```Python\nfrom collections import defaultdict\nclass TrieNode:\n    def __init__(self):\n        self.children = defaultdict(TrieNode)\n        self.isWord = False\n        \nclass Trie:\n    def __init__(self):\n        self.root = TrieNode()\n        self.ret = ""\n\n    def insert(self, word):\n        node = self.root\n        for letter in word:\n            node = node.children[letter]\n        node.isWord = True\n\nclass Solution:            \n    def longestWord(self, words: List[str]) -> str:\n        def dfs(node, path):\n            if not node.isWord:\n                return\n            if len(path) > len(self.ret):\n                self.ret = "".join(path)\n            for letter in node.children:\n                dfs(node.children[letter], path+[letter])\n            \n        words.sort()\n        trie = Trie()\n        trie.root.isWord = True\n        for word in words:\n            trie.insert(word)\n        self.ret = ""\n        dfs(trie.root, [])\n        return self.ret\n```
['Trie', 'Sorting', 'Python', 'Python3']