Count all Prefixes in a Hash Map
Intuition\nIterate over all the workds x prefixes and create a hashmap of all prefix counts. Then just use that to count the score\n\n# Approach\niterate over a
# Intuition\nIterate over all the workds x prefixes and create a hashmap of all prefix counts. Then just use that to count the score\n\n# Approach\niterate over all the workds x prefixes and create a hashmap of all prefix counts. Then just use that to count the score\n\n# Complexity\n- Time complexity:\nO(W x L)\n\nW: number of words\nL: Max length of words\n\n- Space complexity:\nO(W x L)\n\nW: number of words\nL: Max length of words\n\n# Code\n```\nfunc sumPrefixScores(words []string) []int {\n    prefixCounts := make(map[string]int)\n\n    for _, w := range words {\n        for i := 1; i <= len(w); i ++ {\n            prefixCounts[w[:i]]++\n        }\n    }\n\n    res := make([]int, len(words))\n\n    for i, w := range words {\n        for j := 1; j <= len(w); j ++ {\n            res[i] += prefixCounts[w[:j]]\n        }\n    }\n\n    return res\n}\n```
['Go']