trie, java
Code:\n\n    Node root = new Node();  // Trie root.\n    class Node {\n        int score = 0;\n        Node[] child = new Node[26];\n    }\n    \n    public int
**Code:**\n\n    Node root = new Node();  // Trie root.\n    class Node {\n        int score = 0;\n        Node[] child = new Node[26];\n    }\n    \n    public int[] sumPrefixScores(String[] words) {\n        for(String word : words) add(word); // make trie.\n        \n        int [] res = new int[words.length];\n        for(int i=0; i<res.length; i++)\n            res[i] = calc(words[i]);  // build scores.\n        return res;\n    }\n    \n    void add(String str){\n        Node temp = root;\n        for(char ch : str.toCharArray()){\n            if(temp.child[ch-\'a\']==null)\n                temp.child[ch-\'a\'] = new Node();\n            temp.child[ch-\'a\'].score++;\n            temp = temp.child[ch-\'a\'];\n        }\n    }\n    \n    int calc(String str){\n        int ans = 0;\n        Node temp = root;\n        for(char ch : str.toCharArray()){\n            ans += temp.child[ch-\'a\'].score;\n            temp = temp.child[ch-\'a\'];\n        }\n        return ans;\n    }
['Trie', 'Java']