You guys know that the naive solution beats 100% here?
Just wanted to leave it here that for this question the absolute best solution (for the test cases presented) is a naive linear search:\n\n1. Save the dictionar
Just wanted to leave it here that for this question the absolute best solution (for the test cases presented) is a naive linear search:\n\n1. Save the dictionary as is.\n2. Upon `Search` iterate over the dictionary and find any string that differs with a single character.\n\nThis is faster than any dictionary or trie approach. I also tried sorting the dictionary on string sizes and using binary search to find the segment that contains the words of the same size. It didn\'t help either.\n\nExample solution:\n\n```cpp\ninline bool OneCharDiff(const string& a, const string& b) {\n    if (a.size() != b.size()) {\n        return false;\n    }\n    int diff = 0;\n    for (int i = 0; i < a.size() && diff <= 1; ++i) {\n        diff += a[i] != b[i];\n    }\n    return diff == 1;\n}\n\nclass MagicDictionary {\n    vector<string> d;\n    \npublic:\n    MagicDictionary() {}\n    \n    void buildDict(vector<string> dictionary) {\n        d = move(dictionary);\n    }\n    \n    bool search(string searchWord) {\n        for (const string& w : d) {\n            if (OneCharDiff(searchWord, w)) {\n                return true;\n            }\n        }\n        return false;\n    }\n};\n```
[]