Trie DFS Solution C++ || Easy Solution
Code\ncpp []\n// TrieNode class\nclass TrieNode{\npublic:\n    TrieNode* child[26];\n    bool endWord;\n    \n    TrieNode(){\n        endWord = false;\n\n     
# Code\n```cpp []\n// TrieNode class\nclass TrieNode{\npublic:\n    TrieNode* child[26];\n    bool endWord;\n    \n    TrieNode(){\n        endWord = false;\n\n        for (size_t i = 0; i < 26; i++)\n            child[i] = nullptr;\n    }\n};\n\nclass MagicDictionary {\nprivate:    \n    TrieNode *root; // Trie root\n\n    // Method to build the trie tree\n    void buildWord(const string &s){\n        TrieNode *curr = root;\n\n        for(const char &c : s){\n            if(!curr->child[c - \'a\']) curr->child[c - \'a\'] = new TrieNode();\n            curr = curr->child[c - \'a\'];\n        }\n        curr->endWord = true;\n    }\n    \n    // Take in count that you have to make a mandatory\n    // modification in the string, so you HAVE to skip one \n    // and only one character. You can use DFS to try all possible\n    // ways.\n    bool searchWithChange(const string &s, TrieNode *nd, const int idx, bool madeChange){\n        if(!nd)\n            return false;\n        TrieNode *curr = nd;\n\n        for (int i = idx; i < s.size(); i++){\n            if(!madeChange){ // DFS\n                for (int j = 0; j < 26; j++)\n                    if(curr->child[j] && j != s[i] - \'a\')\n                        if(searchWithChange(s, curr->child[j], i + 1, true)) // Recursive call\n                            return true;\n            } \n            // If the string is not complete return false, continue otherwise\n            if(curr->child[s[i] - \'a\']) curr = curr->child[s[i] - \'a\'];\n            else return false;\n        }\n        \n        // Return true if we are at the end of the word and we made a change\n        return curr->endWord && madeChange;\n    }\n\npublic:\n    MagicDictionary() {\n        root = new TrieNode();\n    }\n    \n    void buildDict(vector<string> dictionary) {\n        for(const string &s : dictionary)\n            buildWord(s);\n    }\n    \n    bool search(string searchWord) {\n        return searchWithChange(searchWord, root, 0, false);\n    }\n};\n```
['String', 'Depth-First Search', 'Trie', 'C++']