String Hashing || Java
\npublic int[] sumPrefixScores(String[] words) {\n    int n = words.length, p = 31, m = (int)1e9 + 9;\n    int[] ans = new int[n];\n    long[] hash = new long[n
```\npublic int[] sumPrefixScores(String[] words) {\n    int n = words.length, p = 31, m = (int)1e9 + 9;\n    int[] ans = new int[n];\n    long[] hash = new long[n], p_pow = new long[n];\n    Arrays.fill(p_pow,1);\n    for(int i = 0; i < 1000; i++){\n        Map<Long,Integer> map = new HashMap<>();\n        for(int j = 0; j < n; j++){\n            if(words[j].length() <= i) continue;\n            hash[j] = (hash[j] + (words[j].charAt(i) - \'a\' + 1) * p_pow[j]) % m;\n            p_pow[j] = (p_pow[j] * p) % m;\n            map.put(hash[j], map.getOrDefault(hash[j],0) + 1);\n        }\n        for(int j = 0; j < n; j++){\n            if(words[j].length() <= i) continue;\n            ans[j] += map.get(hash[j]);\n        }\n    }\n    return ans;\n}\n```
[]