Simple C++ solution | TRIE
Intuition\nFor every word, we need to find all the prefixes and get the count of all such prefixes which will be the score of that word.\n\nSince we need to fin
# Intuition\nFor every word, we need to find all the prefixes and get the count of all such prefixes which will be the score of that word.\n\nSince we need to find and store all the prefixes, a Trie will be the best Data Structure to use here.\n\n# Approach\n1. Initialize a trie and insert all the words into the trie.\n2. For every letter in the word, increment the prefixCount of prefix  ending at that letter by 1.\n3. Again iterate over over the words array.\n4. For every word, get all of its prefixes and add the respective prefixCount to score. \n\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(n * m)\nn=size of vector\nm=size of word\n\n# Code\n```cpp []\nstruct Node{\n    Node* links[26];\n    int prefixCount=0;\n\n    bool containsKey(char c){\n        return (links[c-\'a\']!=NULL);\n    }\n\n    void put(char c,Node* node){\n        links[c-\'a\']=node;\n    }\n\n    Node* get(char c){\n        return links[c-\'a\'];\n    }\n\n    void increasePrefixCount(){\n        prefixCount++;\n    }\n\n};\n\n\nclass Solution {\n\nprivate:\n\n    Node* root = new Node();\n\n    void insert(string &word){\n        Node* node = root;\n        for(char &c:word){\n            if(!node->containsKey(c)){\n                node->put(c,new Node());\n            }\n            node=node->get(c);\n            node->increasePrefixCount();\n        }\n    }\n\n    int getScore(string&word){\n        Node* node=root;\n        int score=0;\n        for(char &c:word){\n            node=node->get(c);\n            score+=node->prefixCount;\n        }\n        return score;\n    }\n\npublic:\n    vector<int> sumPrefixScores(vector<string>& words) {\n        for(string &word:words){\n            insert(word);\n        }\n        vector<int>ans;\n        for(string &word:words){\n            ans.push_back(getScore(word));\n        }\n        return ans;\n    }\n};\n```\n\nPlease upvote if you found it useful!!
['Array', 'String', 'Trie', 'Counting', 'C++']