[Python] Trie solution explained
\nclass TrieNode(object):\n    def __init__(self):\n        self.children = {}\n        self.end = False\n\nclass Solution:\n    def longestWord(self, words: Li
```\nclass TrieNode(object):\n    def __init__(self):\n        self.children = {}\n        self.end = False\n\nclass Solution:\n    def longestWord(self, words: List[str]) -> str:\n        root = TrieNode()\n\n        # populate all the elements in the trie\n        # word by word, no need for sorting here\n        for word in words:\n            cur = root\n            for letter in word:\n                if letter not in cur.children:\n                    cur.children[letter] = TrieNode()\n                cur = cur.children[letter]\n            cur.end = True\n            \n        res = \'\'\n        \n        # iterate over all the words\n        # in our words array\n        for word in words:\n            # if the length of the word\n            # isn\'t > our res, there\'s no\n            # point in exploring further\n            # since we want the longest word\n            if len(word) < len(res): continue\n            \n            # start a temp cur var\n            # init at root to iterate\n            # trie for every word\n            cur = root\n            \n            # for every letter in the current\n            # word, traverse the trie and see\n            # that for every letter in this\n            # word, there\'s a node in the trie\n            # which has end = True (i.e. a word \n            # on its own, if not just break out)\n            for letter in word:\n                cur = cur.children[letter]\n                if not cur.end: break\n            \n            # proceed only if you didn\'t break\n            # out of the previous loop (cur.end == True)\n            # and then check if the cur word is longer\n            # than the cur res, or if they are equal in length\n            # use the lexicographically smaller one (word < res)\n            if cur.end and (len(word) > len(res) or (len(word) == len(res) and word < res)):\n                res = word        \n            \n        return res\n```
['Trie', 'Python', 'Python3']