[C++] A bloodily optimized brute force solution with string_view beat 90% time/space
\nclass Solution {\npublic:\n    string longestWord(vector<string>& words) {\n        unordered_set<string_view> dict(begin(words), end(words)); \n        strin
```\nclass Solution {\npublic:\n    string longestWord(vector<string>& words) {\n        unordered_set<string_view> dict(begin(words), end(words)); \n        string ans="";                \n        for(string_view w: dict){ // This will save huge amount of time in case of lots of repetition in words\n            if(w.size() < ans.size() || w.size() == ans.size() && w > ans) continue;            \n            bool valid = true;                                     \n            for(int i = 1; i <= w.size() - 1 && valid; i++)\n               if(!dict.count(w.substr(0,i))) valid = false;\n                \n            if(valid) ans = w;                \n        }\n        return ans;\n    }\n};\n```
[]