Javascript Set easiest
\n/*\nSee this is prefix Tree(Trie)\nSort dict: solve all prefix words and get lexicographical order\nTraverse dict:\n1step check if set has word before itself,
```\n/*\nSee this is prefix Tree(Trie)\nSort dict: solve all prefix words and get lexicographical order\nTraverse dict:\n1step check if set has word before itself, if yes, valid\n2step check if need update res compare string.length\n3step then find longest word with smallest lexicographical order\n*/\nvar longestWord = function(words) {\n    if (!words || words.length == 0) return "";\n    let res = "";\n    let set = new Set(); //store valid word\n    words.sort(); //sort string \n    for (let word of words){\n        let prev = word.substring(0, word.length -1);\n        if (word.length == 1 || set.has(prev)){  //store only one char, or has word before itself\n            res = (word.length > res.length) ? word : res;\n            set.add(word);\n        }\n    }\n    return res;\n};\n```
['JavaScript']