Simple short 7 lines python solution using sorting and set
The idea is to first sort the words, and once sorted, add each word to the resultset, if the prefix of the word word[:-1] is there in the sortedset. \n\nBy comm
The idea is to first sort the words, and once sorted, add each word to the resultset, if the prefix of the word word[:-1] is there in the sortedset. \n\nBy commutative property, if the prefix is there in the resultset, then that implies all the prefixes of length 1, 2, 3 .. are also there in the resultset, due to sorted data.\n\nAlso maintaining a global res_word and updating it every time we add a word to the resultset, makes it easy to find the final result.\n\n```\n    def longestWord(self, words):\n        words, resword, res = sorted(words), '', set()\n        for word in words:\n            if len(word) == 1 or word[:-1] in res:\n                res.add(word)\n                resword = word if resword == '' else word if len(word) > len(resword) else resword\n        return resword\n```
[]