[C++] ✅|| 2 Approach | HashMap & Trie | Easy to understand 🚀
Approach - 1: (Using Hashmap) \n\nclass Solution {\npublic:\n    vector<int> sumPrefixScores(vector<string>& words) \n    {\n        unordered_map<string, int>m
Approach - 1: (Using Hashmap) \n```\nclass Solution {\npublic:\n    vector<int> sumPrefixScores(vector<string>& words) \n    {\n        unordered_map<string, int>mp;\n        for (int i=0;i<words.size();i++)\n        {\n            string temp = "";\n            string curr = words[i];\n            \n            for (int j=0;j<curr.size();j++)\n            {\n                temp += curr[j];\n                mp[temp] += 1;\n            }\n        }\n        \n        vector<int>ans;\n        for (int i=0;i<words.size();i++)\n        {\n            string temp = "";\n            string curr = words[i];\n            int count = 0;\n            \n            for (int j=0;j<curr.size();j++)\n            {\n                temp += curr[j];\n                if (mp.find(temp) != mp.end())   count += mp[temp];\n            }\n            ans.push_back(count);\n        }\n        \n        return ans;\n    }\n};\n```\n\nApproach - 2: (Using Trie)\n```\nstruct Node {\n    Node* link[26];\n    bool flag = false;\n    int prefixCount = 0;\n\n    void put(char ch, Node* node) {\n        link[ch - \'a\'] = node;\n    }\n    \n    bool containsKey(char ch) {\n        return (link[ch - \'a\'] != NULL);\n    }\n    \n    Node* get (char ch) {\n        return link[ch - \'a\'];\n    }\n    \n    bool isEnd() {\n        return flag;\n    }\n    \n    void setEnd() {\n        flag = true;\n    }\n    \n    void increasePrefixCount () {\n        prefixCount += 1;\n    }\n    \n    int getPrefixCount() {\n        return prefixCount;\n    }\n};\n\nclass Solution {\nprivate:\n    Node* root;\npublic:\n    Solution () \n    {\n        root = new Node();\n    }\n    \n    vector<int> sumPrefixScores(vector<string>& words) \n    {\n        for (int i=0;i<words.size();i++)\n        {\n            string word = words[i];\n            Node* node = root;\n            \n            for (int j=0;j<word.size();j++)\n            {\n                if (!node -> containsKey(word[j])) \n                {\n                    node->put(word[j], new Node());\n                }\n                node = node -> get(word[j]);\n                node -> increasePrefixCount();\n            }\n            \n            node -> setEnd();\n        }\n        \n        vector<int>ans;\n        for (int i=0;i<words.size();i++)\n        {\n            string word = words[i];\n            Node* node = root;\n            int count = 0;\n            \n            for (int j=0;j<word.size();j++)\n            {\n                if (node -> containsKey(word[j]))\n                {\n                    // count += node -> getPrefixCount();\n                    node = node -> get(word[j]);\n                    count += node -> getPrefixCount();\n                }\n            }\n            ans.push_back(count);\n        }\n        \n        return ans;\n        \n    }\n};\n```\n\n
['Trie', 'C']