C++ || EASY TO UNDERSTAND || using SET
\nclass Solution {\npublic:\n    static bool comp(string a,string b)\n    {\n        if(a.size()!=b.size())\n        return a.size()<b.size();\n        else\n  
```\nclass Solution {\npublic:\n    static bool comp(string a,string b)\n    {\n        if(a.size()!=b.size())\n        return a.size()<b.size();\n        else\n        return a>b;\n    }\n    string longestWord(vector<string>& words) {\n        vector<string> v;\n        unordered_set<string> s;\n        int n=words.size(),c;\n        for(int i=0;i<n;i++)\n        s.insert(words[i]);\n        for(int i=0;i<n;i++)\n        {\n            c=0;\n            string str;\n            int k;\n            for(int j=1;j<=words[i].size();j++)\n            {\n                str=words[i].substr(0,j);\n                k=str.size();\n                if(s.find(str)!=s.end())\n                c++;\n            }\n            if(c==k)\n            v.push_back(str);\n        }\n        if(v.size()==0)\n        return "";\n        sort(v.begin(),v.end(),comp);\n        return v[v.size()-1];\n    }\n};\n```\n**Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are always welcome**
['String', 'C', 'Ordered Set']