JAVA | Trie Data Structure
Code\njava []\nclass TrieNode {\n    TrieNode [] children = new TrieNode[26];\n    int count = 0;\n}\nclass Solution {\n    TrieNode root = new TrieNode();\n   
# Code\n```java []\nclass TrieNode {\n    TrieNode [] children = new TrieNode[26];\n    int count = 0;\n}\nclass Solution {\n    TrieNode root = new TrieNode();\n    public void add(String word) {\n        TrieNode curr = root;\n        for (char c : word.toCharArray()) {\n            int idx = c - \'a\';\n            if (curr.children[idx] == null)\n                curr.children[idx] = new TrieNode();\n            curr = curr.children[idx];\n            curr.count += 1;\n        }\n    }\n    public int sum(String word) {\n        TrieNode curr = root;\n        int res = 0;\n        for (char c : word.toCharArray()) {\n            int idx = c - \'a\';\n            curr = curr.children[idx];\n            res += curr.count;\n        }\n        return res;\n    }\n    public int[] sumPrefixScores(String[] words) {\n        int [] res = new int[words.length];\n        for (String word : words) add(word);\n        for (int i = 0 ; i < words.length ; i++)\n            res[i] = sum(words[i]);\n        return res;\n    }\n}\n```
['Trie', 'Counting', 'Java']