Python Trie
\nclass TrieNode(object):\n    def __init__(self):\n        self.node ={}\n        self.end = False\n        \n    def get(self,c):\n        return self.node.ge
```\nclass TrieNode(object):\n    def __init__(self):\n        self.node ={}\n        self.end = False\n        \n    def get(self,c):\n        return self.node.get(c)\n    \n    def put(self, c, new_node):\n        self.node[c] = new_node\n\nclass Trie():\n    def __init__(self):\n        self.root = TrieNode()\n        self.longest_word = \'\'\n        self.flag=False\n        \n    def insert(self, word):\n        temp_node = self.root\n        for c in word:\n            if not temp_node.get(c):\n                temp_node.put(c, TrieNode())\n            temp_node = temp_node.node[c]\n        temp_node.end = True\n     \n    def find_longest_string(self,tnode,res):\n        \n        for n in tnode.node.keys():\n            if self.flag:\n                self.flag=False\n                res=res[:-1]\n            if tnode.node[n].end:\n\t\t\t#if its the end of word add that to temp res and continue with its children\n                res+=n\n                self.find_longest_string(tnode.node[n],res)\n            else:\n                self.largest_string(res)\n        self.largest_string(res)\n        self.flag=True\n        \n    def largest_string(self,res):\n        if len(res)>len(self.longest_word):\n            self.longest_word = res\n        if len(res)==len(self.longest_word):\n            self.longest_word = self.longest_word if self.longest_word < res else                      res\n        \nclass Solution(object):\n    def longestWord(self, words):\n        """\n        :type words: List[str]\n        :rtype: str\n        """\n        t = Trie()\n        for word in words:\n            t.insert(word)\n        t.find_longest_string(t.root, \'\')\n        return t.longest_word\n```
[]