C++ || Easiest Trie Implementation || Longest String With All Prefix Present In The Given Array
Kindly Upvote\n\nclass Solution {\npublic:\n    class TrieNode{\n        public:\n        char data;\n        TrieNode* child[26];\n        bool isWord;\n      
**Kindly Upvote**\n```\nclass Solution {\npublic:\n    class TrieNode{\n        public:\n        char data;\n        TrieNode* child[26];\n        bool isWord;\n        TrieNode(){\n            this->data = \'$\';\n            for(int i = 0;i < 26;i++){\n                this->child[i] = nullptr;\n            }\n            this->isWord = false;\n        }\n    };\n    class Trie{\n        public:\n        TrieNode* root;\n        Trie(){\n            root = new TrieNode();\n        }\n        void insertHelp(string word,TrieNode* root){\n            if(word.length() == 0){\n                root->isWord = true;\n                return;\n            }\n            int index = word[0] - \'a\';\n            if(root->child[index] == nullptr){\n                TrieNode* c = new TrieNode();\n                c->data = word[0];\n                root->child[index] = c;\n            }\n            insertHelp(word.substr(1),root->child[index]);\n            return;\n        }\n        void insert(string word){\n            insertHelp(word,root);\n        }\n        bool isGoodHelp(string word,TrieNode* root){\n            if(word.length() == 0){\n                return root->isWord;\n            }\n            int index = word[0] - \'a\';\n            if(root->child[index] == nullptr || root->child[index]->isWord == false){\n                return false;\n            }\n            return isGoodHelp(word.substr(1),root->child[index]);\n        }\n        bool isGood(string word){\n            return isGoodHelp(word,root);\n        }\n    };\n    string longestWord(vector<string>& words) {\n        Trie PrefixTree;\n        for(auto it:words){\n            PrefixTree.insert(it);\n        }\n        string ans = "";\n        for(auto it:words){\n            if(PrefixTree.isGood(it)){\n                if(it.size() > ans.size()){\n                    ans = it;\n                }\n                else if(it.size() == ans.size()){\n                    ans = min(ans,it);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```\n
['Trie', 'C', 'C++']