[Java] Best solution in design scenario - Using Trie Tree
java\nclass Solution {\n    public int countPrefixes(final String[] words, final String s) {\n        final TrieNode root = new TrieNode();\n\n        // Insert
```java\nclass Solution {\n    public int countPrefixes(final String[] words, final String s) {\n        final TrieNode root = new TrieNode();\n\n        // Insert all words in Trie\n\n        for(final String word : words) {\n            TrieNode curr = root;\n\n            for(int i = 0; i < word.length(); ++i) {\n                final int idx = word.charAt(i) - \'a\';\n\n                if(curr.children[idx] == null)\n                    curr.children[idx] = new TrieNode();\n\n                curr = curr.children[idx];\n            }\n\n            curr.count++;\n        }\n\n        int count = 0;\n        TrieNode curr = root;\n\n        for(int i = 0; i < s.length() && curr.children[s.charAt(i) - \'a\'] != null; ++i) {\n            curr = curr.children[s.charAt(i) - \'a\'];\n            count += curr.count;\n        }\n\n        return count;\n    }\n\n    private class TrieNode {\n        public int count;\n        public TrieNode[] children;\n\n        public TrieNode() {\n            this.count = 0;\n            this.children = new TrieNode[26];\n        }\n    }\n}\n```
['Java']