Simple Solution Using Trie Tree
The question gives Intution of Trie tree as storing all the prefixes will cause TLE\n\nWith the standard implementation of trie tree we can keep a array of coun
The question gives Intution of Trie tree as storing all the prefixes will cause TLE\n\nWith the standard implementation of trie tree we can keep a array of count that will count the frequency of that charcater\n\n=>> Below is the simple CPP implementation\n\n```\nstruct Node{\n    bool flag=false;\n    int count[26] = {0};\n    Node* links[26];\n\t// Increment count while getting the next node\n    Node* get(char ch){\n        count[ch-\'a\']++;\n        return links[ch-\'a\'];\n    }\n\t// As we need not to increment count when we are getting to build ans\n    Node* get2(char ch){\n        // count[ch-\'a\']++;\n        return links[ch-\'a\'];\n    }\n    int getCount(char ch){\n        return count[ch-\'a\'];\n    }\n\t// Adding next character to trie\n    void put(char ch,Node* temp){\n        // count[ch-\'a\']++;\n        links[ch-\'a\']=temp;\n    }\n    bool containsKey(char ch){\n        return links[ch-\'a\']!=NULL;\n    }\n};\n\nclass Trie {\npublic:\n    Node *root;\n    Trie() {\n        root = new Node();\n    }\n    void insert(string s){\n        Node* temp=root;\n        for(int i=0;i<s.size();i++){\n            if(!temp->containsKey(s[i]))\n                temp->put(s[i],new Node());\n            temp=temp->get(s[i]);\n        }\n        temp->flag=true;\n    }\n    \n    int getAns(string s) {\n        Node* temp = root;\n        int ans = 0;\n        for(int i=0;i<s.size();i++) {\n            ans += temp->getCount(s[i]);\n            temp = temp->get2(s[i]);\n        }\n        return ans;\n    }\n};\n\n\nclass Solution {\npublic:\n    vector<int> sumPrefixScores(vector<string>& words) {\n        int n = words.size();\n        Trie trie;\n        for(string s:words) trie.insert(s);\n        vector<int> ans(n,0);\n        for(int i=0;i<n;i++) {\n            ans[i] = trie.getAns(words[i]);\n        }\n        return ans;\n    }\n};\n```
['Tree', 'Trie', 'C++']