Java Trie solution
\nclass Solution {\n    int maxLen = 0;\n    String longestWord;\n\t\n    public String longestWord(String[] words) {\n        TrieNode root = buildTrie(words);
```\nclass Solution {\n    int maxLen = 0;\n    String longestWord;\n\t\n    public String longestWord(String[] words) {\n        TrieNode root = buildTrie(words);\n        for (int i = 0; i < 26; ++i) {\n            if (root.children[i] != null) {\n                dfs(root.children[i], 1);\n            }\n        }\n        return longestWord;\n    }\n    \n    TrieNode buildTrie(String[] words) {\n        TrieNode root = new TrieNode();\n        \n        for (String word : words) {\n            TrieNode p = root;\n            \n            for (char c : word.toCharArray()) {\n                if (p.children[c - \'a\'] == null) {\n                    p.children[c - \'a\'] = new TrieNode();\n                }\n                p = p.children[c - \'a\'];\n            }\n            p.isWord = true;\n            p.word = word;\n        }\n        return root;\n    }\n    \n    void dfs(TrieNode root, int depth) {\n        if (!root.isWord)   return;\n        \n        if (depth > maxLen) {\n            maxLen = depth;\n            longestWord = root.word;\n        }\n        \n        for (int i = 0; i < 26; ++i) {\n            if (root.children[i] != null) {\n                dfs(root.children[i], depth + 1);\n            }\n        }\n    }\n    \n    class TrieNode {\n        TrieNode[] children = new TrieNode[26];\n        boolean isWord;\n        String word;\n    }\n}\n```
[]