A different approach using Recursion. Slower than tries, but unique.
\nclass Solution {\npublic:\n    int solve(string w, vector <string> &words, unordered_set <string> &st, int ctr)\n    {\n        if(w=="")\n            return 
```\nclass Solution {\npublic:\n    int solve(string w, vector <string> &words, unordered_set <string> &st, int ctr)\n    {\n        if(w=="")\n            return ctr;\n        \n        string t=w;\n        t.pop_back();\n        if(st.find(t)!=st.end() || t=="")\n        {\n            return solve(t, words, st, ctr+1);\n        }\n        else\n            return -1;\n    }\n    string longestWord(vector<string>& words) \n    {\n        unordered_set <string> st;\n        for(string w: words)\n            st.insert(w);\n        \n        string ans="";\n        for(string w: words)\n        {\n            int len=solve(w, words, st, 0);\n            //cout<<len<<" "<<ans.size()<<endl;\n            if(len!=-1 && len>ans.size())\n            {\n                ans=w;\n                //cout<<ans<<endl;\n            }\n            else if(len==ans.size())\n                ans=min(ans, w);\n        }\n        \n        return ans;\n    }\n};\n```
['Recursion', 'C', 'C++']