Easy to understand (using set) (C++) (with explanation).
Pretty straightforward implementation:\n\n\nclass Solution {\npublic:\n    \n//The comparator is used for sorting the set elements when they are inserted.\n    
Pretty straightforward implementation:\n\n````\nclass Solution {\npublic:\n    \n//The comparator is used for sorting the set elements when they are inserted.\n    struct myComp {\n        bool operator()(auto& lhs, auto& rhs) const{\n            if(lhs.size() > rhs.size())\n                return true;\n            if(lhs.size() == rhs.size())\n                return lhs<rhs;\n            return false;\n        }\n    };\n    \n    string longestWord(vector<string>& words) {\n        if(words.empty())\n            return "";\n        \n        //create a set such that the elements are ordered as per their decreasing lengths.  If the lengths are equal, then they are ordered lexicographically.  \n        set<string, myComp> s(words.begin(), words.end());\n        \n        int i=1;\n        for(auto& each : s) {\n            for(i=1; i<each.size(); i++) {\n                //Find the substring starting from the 0th character to `i`\n                string str = each.substr(0, i);\n                if(s.find(str)==s.end())\n                    break;\n            }\n            if (i==each.size()) return each;\n        }\n        \n        return "";\n    }\n};\n````
['C', 'Ordered Set']