Java | Roling Hash
\nclass Solution\n{\n    final int m = 1023;\n    public int[] sumPrefixScores(String[] words)\n    {\n        HashMap<Long,Integer> map = new HashMap<>();\n   
```\nclass Solution\n{\n    final int m = 1023;\n    public int[] sumPrefixScores(String[] words)\n    {\n        HashMap<Long,Integer> map = new HashMap<>();\n        for(String S : words)\n        {\n            char[] s = S.toCharArray();\n            long hash_so_far = 0L;\n            int n = s.length;\n            for (int i = 0; i < n; i++)\n            {\n                hash_so_far = hash_so_far*m+s[i];\n                map.put(hash_so_far,map.getOrDefault(hash_so_far,0)+1);\n            }\n        }\n        int cur = 0;\n        int[] ret = new int[words.length];\n        for(String S : words)\n        {\n            char[] s = S.toCharArray();\n            long hash_so_far = 0L;\n            int n = s.length;\n            for (int i = 0; i < n; i++)\n            {\n                hash_so_far = hash_so_far*m+s[i];\n                ret[cur] += map.get(hash_so_far);\n            }\n            cur++;\n        }\n        return ret;\n    }\n}\n```
['Rolling Hash', 'Java']