Simple Python code || Trie, single scan
Sort the list to make sure it\'s in alphabetic order (so that we don\'t need to update previously-visited longer words\' values, and also make sure for same len
Sort the list to make sure it\'s in alphabetic order (so that we don\'t need to update previously-visited longer words\' values, and also make sure for same length of result, the alphabetic order is in place).\n\nWe just scan each word and add to Trie, while keep counting whether it can be built letter by letter (cur.value == len(word)) and longer than previous res.\n\n```\nclass TrieNode:\n    def __init__(self, val):\n        self.children = {}\n        self.value = val\n        self.endOfWord = False\n        \nclass Solution:\n    def longestWord(self, words: List[str]) -> str:\n        root = TrieNode(0)\n        maxLen = 0\n        res = ""\n        for word in sorted(words):\n            cur = root\n            count = 0\n            for letter in word:\n                if letter not in cur.children:\n                    cur.children[letter] = TrieNode(count)\n                cur = cur.children[letter]\n                if cur.endOfWord: count += 1\n            cur.endOfWord = True\n            cur.value += 1\n            if cur.value == len(word) and cur.value > maxLen:\n                maxLen = cur.value\n                res = word\n        return res\n```
['Trie', 'Python', 'Python3']