Simple solution using Trie in C++
\nstruct trie{\n    \n    trie* children[26];\n    string val;\n};\n\ntrie* newnode(){\n    \n    trie* curr=new trie();\n    for(int i=0;i<26;i++){\n        cu
```\nstruct trie{\n    \n    trie* children[26];\n    string val;\n};\n\ntrie* newnode(){\n    \n    trie* curr=new trie();\n    for(int i=0;i<26;i++){\n        curr->children[i]=NULL;\n    }\n    curr->val="";\n    return curr;\n}\n\nvoid insert(trie *&root,string word){\n    \n    trie* curr=root;\n    for(int i=0;i<word.size();i++){\n        int index=word[i]-\'a\';\n        \n        if(curr->children[index]==NULL){\n            curr->children[index]=newnode();\n        }\n        curr=curr->children[index];\n    }\n    curr->val=word;\n}\n\nvoid dfs(trie* root,string &ans){\n    \n    for(auto child:root->children){\n        if(child!=NULL && child->val.size()>0){\n            if(child->val.size()>ans.size()){\n                ans=child->val;\n            }\n            dfs(child,ans);\n        }\n    }\n}\n\nclass Solution {\npublic:\n    trie* root;\n    string ans="";\n    string longestWord(vector<string>& words) {\n        \n        root=newnode();\n        for(int i=0;i<words.size();i++){\n            insert(root,words[i]);\n        }\n        \n        dfs(root,ans);\n        return ans;\n    }\n};\n```
[]