Python solution using sort and set
Intuition\n1. sort the words list as their length and lexicographical order.\n2. use seen to record words whose prefix words[:-1] is also in seen. \n\nclass Sol
**Intuition**\n1. sort the `words` list as their length and lexicographical order.\n2. use `seen` to record words whose prefix `words[:-1]` is also in seen. \n```\nclass Solution:\n    def longestWord(self, words: List[str]) -> str:\n        res = \'\'\n        words.sort(key=lambda word: (len(word), word))\n        seen = {\'\'}\n        for i in range(len(words)):\n            if words[i][:-1] in seen:\n                seen.add(words[i])\n                if len(words[i]) > len(res) or len(words[i]) == len(res) and words[i] <= res:\n                    res = words[i]\n        return res\n```
[]