Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.
Note that the word should be built from left to right with each additional character being added to the end of a previous word.
Input: words = ["w","wo","wor","worl","world"]
Output: "world"
Explanation: The word "world" can be built one character at a time by "w", "wo", "wor", and "worl".
Input: words = ["a","banana","app","appl","ap","apply","apple"]
Output: "apple"
Explanation: Both "apply" and "apple" can be built from other words in the dictionary. However, "apple" is lexicographically smaller than "apply".
1 <= words.length <= 10001 <= words[i].length <= 30words[i] consists of lowercase English letters.The brute force approach involves iterating through each word and checking if all its prefixes exist in the given list. We can achieve this by using a HashSet to store all words and checking if each prefix of a word exists in the set. If so, keep track of the longest valid word encountered so far.
A Trie is an efficient data structure to store and retrieve words, especially useful in prefix queries. By inserting all words into a Trie, we can efficiently check if a word can be built by other words. We traverse the Trie to find the deepest node that represents a complete buildable word, which will be our answer.