Python solution
Time complexity: O(nl^2), space complexity: O(l), where n = len(words), and l is the length of the longest string in words.\n\nclass Solution:\n    def longestW
Time complexity: `O(nl^2)`, space complexity: `O(l)`, where `n = len(words)`, and `l` is the length of the longest string in `words`.\n```\nclass Solution:\n    def longestWord(self, words):\n        """\n        :type words: List[str]\n        :rtype: str\n        """\n        res = None\n        maxlen = 0\n        look_up = set(words)\n        for word in words:\n            if len(word) >= maxlen:\n                if len(word) == maxlen:\n                    if word < res:\n                        if all(word[:i] in look_up for i in range(1, len(word))):\n                            res = word\n                else:\n                    if all(word[:i] in look_up for i in range(1, len(word))):\n                        res = word\n                        maxlen = len(word)\n        return res\n```
[]