C++ Easy Solution | Trie
I have created Trie data structure with array of pointers next to point all alphabets and wordCount which will store number of words having prefix string ending
I have created `Trie` data structure with array of pointers `next` to point all alphabets and `wordCount` which will store number of words having prefix string ending at current node.\n\nFor example - consider array of strings `["abc", "ab", "b"]`\nTrie will be like -\n```\n\t\t\t\t\t\t\t Root\n\t\t\t\t\t\t wordCount = 0\n\t\t\t\t\t\t/              \\\n\t\t\t\t      \'a\'               \'b\'\n\t\t    \twordCount = 2       wordCount = 1\n\t\t          /\n\t\t       \'b\'\n\t\t  wordCount = 2\n\t\t\t/\n\t\t\'c\'\n   wordCount = 1\n\n```\n\nThen for each word i have traversed the trie data structure and added `wordCount` for each character.\n\n```\nclass trie {\n    public:\n    trie* next[26] = {};\n    int wordCount;\n    trie(){\n        wordCount = 0;\n    }\n};\n\nclass Solution {\npublic:\n    vector<int> sumPrefixScores(vector<string>& words) {\n        trie* root = new trie();\n        int n = words.size();\n        \n\t\t// constructing trie data structure\n        for (int i = 0; i < n; i++) {\n            auto cur = root;\n            for (char c : words[i]) {\n                if (!cur -> next[c - \'a\'])\n                    cur -> next[c - \'a\'] = new trie();\n                cur = cur -> next[c - \'a\'];\n                cur -> wordCount++;\n            }\n        }\n        \n\t\t// calculating ans for each word\n        vector<int> ans(n);\n        for (int i = 0; i < n; i++) {\n            auto cur = root;\n            for (int j = 0; j < words[i].size(); j++) {\n                cur = cur -> next[words[i][j] - \'a\'];\n                ans[i] += cur -> wordCount;\n            }\n        }\n        \n        return ans;\n    }\n};\n```\nHope it helps and feel free to ask if you have any doubts :)
['Trie', 'C']