Easy Trie C++ Solution
\nclass TrieNode {\npublic:\n    TrieNode* children[26];\n    bool isEnd;\n\n    TrieNode() {\n        memset(children, 0, sizeof(children));\n        isEnd = f
```\nclass TrieNode {\npublic:\n    TrieNode* children[26];\n    bool isEnd;\n\n    TrieNode() {\n        memset(children, 0, sizeof(children));\n        isEnd = false;\n    }\n};\n\nclass Solution {\npublic:\n\n    TrieNode *root;\n\n    void addWord(string word) {\n        TrieNode *curr = root;\n        for(auto ch: word) {\n            int index = ch - \'a\';\n            if(curr->children[index] == NULL) {\n                curr->children[index] = new TrieNode();\n            }\n            curr = curr->children[index];\n        }\n        curr->isEnd = true;\n    }\n\n    bool search(string word) {\n        TrieNode *curr = root;\n        for(auto ch: word) {\n            int index = ch - \'a\';\n            if(curr->children[index] == NULL) {\n                return false;\n            }\n            curr = curr->children[index];\n        }\n        if(curr != NULL and curr->isEnd == true) {\n            return true;\n        }  \n        return false;\n    }\n\n    bool isValid(string word) {\n        TrieNode *curr = root;\n        for(auto ch: word) {\n            int index = ch - \'a\';\n            curr = curr->children[index];\n            if(!curr->isEnd) {\n                return false;\n            }\n        }\n        return true;\n    }\n    string longestWord(vector<string>& words) {\n\n        // My approach is to make a trie and see those terminal nodes who have already \n        // have the terminal nodes in their path i.e count == n-1;\n        // make a max count and update the answer \n\n        root = new TrieNode();\n\n        for(auto word: words) {\n            addWord(word);\n        }\n        string ans = "";\n        for(auto word: words) {\n            if(isValid(word)) {\n                if(word.size() > ans.size()) {\n                    ans = word;\n                } else if(word.size() == ans.size()) {\n                    ans = min(ans, word);\n                }\n            }\n        }\n\n        return ans;\n        \n    }\n};\n```
['Trie', 'C++']