✅NO SORTING REQUIRED...
\nclass Solution {\n    class trie{\n        struct node{\n            node* links[26];\n            bool flag=false;\n        };\n    public:\n        node* ro
```\nclass Solution {\n    class trie{\n        struct node{\n            node* links[26];\n            bool flag=false;\n        };\n    public:\n        node* root;\n        trie(){\n            root=new node();\n        }\n        void insert(string word){\n            node* nd=root;\n            for(int i=0;i<word.size();i++){\n                if(nd->links[word[i]-\'a\']==NULL){\n                    nd->links[word[i]-\'a\']=new node();\n                }\n                nd=nd->links[word[i]-\'a\'];\n            }\n            nd->flag=true;\n        }\n        bool search(string word){\n            node* nd=root;\n            for(int i=0;i<word.size();i++){\n                if(nd->links[word[i]-\'a\']==nullptr)\n                    return false;\n                nd=nd->links[word[i]-\'a\'];\n            }\n            return nd->flag;\n        }\n    };\npublic:\n    string longestWord(vector<string>& words) {\n        string ans="";\n        trie *t1=new trie();\n        for(auto&it:words)t1->insert(it);\n        for(auto&it:words){\n            bool gotIt=true;\n            for(int i=1;i<it.size();i++){\n                if(!t1->search(it.substr(0,i))){\n                    gotIt=false;\n                    break;\n                }\n            }\n            if(gotIt){\n                if(it.size()>ans.size())ans=it; //if current string has greater size update it\n                if(it.size()==ans.size()&&it<ans)ans=it; //if current string is lexicographicaly smaller update it\n            }\n        }\n        return ans;\n    }\n};\n```
['String', 'Trie', 'String Matching', 'C++']