C++ | Trie + search Prefixes
cpp\nclass TrieNode {\npublic:\n    vector<TrieNode*> child;\n    int availablePrefix;\n};\n\nconst int CHILD_COUNT = 26;\nconst int nax = 1e7 + 9;\nTrieNode po
```cpp\nclass TrieNode {\npublic:\n    vector<TrieNode*> child;\n    int availablePrefix;\n};\n\nconst int CHILD_COUNT = 26;\nconst int nax = 1e7 + 9;\nTrieNode pool[nax];\nint cnt;\nTrieNode *getNode() {\n    auto t = &pool[cnt++];\n    t->child.resize(CHILD_COUNT);\n    for (int i = 0; i < CHILD_COUNT; ++i) {\n        t->child[i] = nullptr;\n    }\n    t->availablePrefix = 0;\n    return t;\n}\n\nclass Solution {\npublic:\n    TrieNode *root;\n    //this would insert all the prefixes of the current string\n    //in to the TRIE\n    void insert(const string &word) {\n        auto ptr = root;\n        for (char ch: word) {\n            int idx = ch - \'a\';\n            if (!ptr->child[idx]) {\n                ptr->child[idx] = getNode();\n            }\n            ptr = ptr->child[idx];\n            ptr->availablePrefix += 1;\n        }\n    }\n    \n    //This searches a string in TRIE and counts \n    //all the prefixes along the path\n    int search (const string &word) {\n        auto ptr = root;\n        int prefixCount = 0;\n        for (char ch: word) {\n            int idx = ch - \'a\';\n            if (!ptr->child[idx]) {\n                return prefixCount;\n            }\n            ptr = ptr->child[idx];\n            prefixCount += ptr->availablePrefix;\n        }\n        return prefixCount;\n    }\n    vector<int> sumPrefixScores(vector<string>& words) {\n        cnt = 0;\n        root = getNode();\n        for (const string &s: words) {\n            insert(s);\n        }\n        vector<int> result;\n        for (const string &s: words) {\n            result.push_back(search(s));\n        }\n        return result;\n    }\n};\n```
[]