EASY TRIE SOLUTION C++
Code\n\nclass Solution {\npublic:\n    struct Node {\n        Node * links[26];\n        bool flag = false;\n        bool isContains(char ch){       // Node has
# Code\n```\nclass Solution {\npublic:\n    struct Node {\n        Node * links[26];\n        bool flag = false;\n        bool isContains(char ch){       // Node has ch or not\n            return links[ch-\'a\'] != NULL;\n        }\n        void put (char ch, Node * node){\n            links[ch-\'a\'] = node;\n        }\n        Node* get(char ch){\n            return links[ch-\'a\'];\n        }\n    };\n    class Trie {\n    private : Node * root;\n    public:\n        Trie() {\n            root = new Node();\n        }\n        \n        void insert(string word) {\n            Node * node = root;\n            int n = word.size();\n            for(int i = 0;i<n;i++){\n                if(!(node ->isContains(word[i]))){       // if node doesn\'t contain word[i]\n                    node->put(word[i],new Node());\n                }\n                node = node->get(word[i]);          // move forward\n            }\n            node->flag = true;                      // word is end here mark flag as true \n        }\n        bool isComplete(string &word){\n                Node * node = root;\n                int n = word.size();\n                for(int i =0;i<n;i++){         // already inserted the string so it will always contain so need to check isContain\n                    node = node->get(word[i]);\n                    if(node->flag == false) return false;       // check flag in each step to assure that all the prefixes of word exists\n                }\n                return true;\n            }\n    };\n    string longestWord(vector<string>& words) {\n        Trie trie;\n        for(auto i : words){\n            trie.insert(i);\n        }\n            string ans = "";\n        for(auto i : words){\n            if(trie.isComplete(i)){\n                if(ans.size()<i.size()) ans = i;\n                if(ans.size() == i.size()) ans = min(ans,i);\n            }    \n        }\n        return ans;\n    }\n};\n```
['C++']