Hashing C++ easy to understand
The hashing technique is simple. The algorithm states that\n1) Assign a hash code to all prefixes of a word ( Using any hash function or Rabin Karp algorithm). 
The hashing technique is simple. The algorithm states that\n1) Assign a hash code to all prefixes of a word ( Using any hash function or Rabin Karp algorithm). Repeat this for every word in the list of words.\n2) Alongside maintain a frequency map for the hash code, or the prefix, which maintains the number of occurrences of the prefix or the hash code.\n3) Now the score of a word is defined as the sum of occurrences of prefixes present in the string from the map that we made earlier.\nThat is the number of times a prefix present in \'word\' appeared across the entire list of words. Sum for all such prefixes in the word is its score.\n\nStoring the hash code in an unordered map gives TLE, so its better to calculate the hash codes again when calculating the scores of the words.\n\n\n```\nclass Solution {\npublic:\n    long long mod= 1e9;\n    \n    void assignHashCode(string& s,unordered_map<long long, int>& hash_code_prefix_freq)\n    {\n        int n= s.size();\n        vector<long long> p(n);\n        long long temp= 37;\n        \n        for(int i=0;i<n;i++)\n        {\n            p[i]= temp;\n            temp= temp % mod * 37 % mod;\n        }\n        \n        long long hc=0;\n        string word="";\n        for(int i=0;i<n;i++)\n        {\n            word.push_back(s[i]);\n            hc+= p[i]% mod* s[i]% mod;\n            hash_code_prefix_freq[hc]++;\n        }\n    }\n    \n    int calculateScore(string& s, unordered_map<long long, int>& hash_code_prefix_freq)\n    {\n        int n= s.size();\n        int score=0;\n        \n        vector<long long> p(n);\n        long long temp= 37;\n        \n        for(int i=0;i<n;i++)\n        {\n            p[i]= temp;\n            temp= temp % mod * 37 % mod;\n        }\n        \n        long long hc=0;\n        string word="";\n        for(int i=0;i<n;i++)\n        {\n            word.push_back(s[i]);\n            hc+= p[i]% mod* s[i]% mod;\n            score+= hash_code_prefix_freq[hc];\n        }\n        \n        return score;\n    }\n    \n    vector<int> sumPrefixScores(vector<string>& words) {\n        \n        unordered_map<long long, int> hash_code_prefix_freq;\n        unordered_map<string, long long> hash_codes;\n        \n        for(auto word: words)\n        {\n            assignHashCode(word,hash_code_prefix_freq); // assign hash code to every prefix in the string and calculate freq\n        }\n        \n        vector<int> scores;\n        for(auto word: words)\n        {\n            int score= calculateScore(word,hash_code_prefix_freq); // find hash code of every prefix and sum frequencies of prefix\n            scores.push_back(score);\n        }\n        \n        return scores; \n    }\n};\n```
['C']