Easy peasy || Trie
Using normal trie implementation with a branch property which at any node wil tell us the total number of branches that are merged with the current path i.e, th
Using normal trie implementation with a **branch** property which at any node wil tell us the total number of branches that are merged with the current path i.e, the total number of prefixes ending at the current node.\nImplementing this and storing all the string in that trie will be a key to that answer, because after than you just have to traverse the path of your given string adding up all the branches count you see.\n\n```\nclass Solution {\n    class Node{\n        char ch;\n        Node[] links;\n        boolean isEnd;\n        int branch;\n        Node(char ch){\n            this.ch=ch;\n            links=new Node[26];\n            branch=1;\n        }\n    }\n    Node root;\n    public Solution() {\n        this.root=new Node(\'*\');\n    }\n    \n    public void insert(String word) {\n        Node curr=this.root;\n        for(int i=0;i<word.length();i++){\n            char ch=word.charAt(i);\n            if(curr.links[ch-\'a\']!=null){\n                curr.links[ch-\'a\'].branch++;\n                curr=curr.links[ch-\'a\'];\n            }\n            else{\n                curr.links[ch-\'a\']=new Node(ch);\n                curr=curr.links[ch-\'a\'];\n            }\n        }\n        curr.isEnd=true;\n    }\n    \n    public int startsWith(String prefix) {\n        Node curr=this.root;\n        int res=0;\n        for(int i=0;i<prefix.length();i++){\n            char ch=prefix.charAt(i);\n            if(curr.links[ch-\'a\']!=null){\n                res+=curr.links[ch-\'a\'].branch;\n                curr=curr.links[ch-\'a\'];\n            }\n            else{\n                return res;\n            }\n        }\n        return res;\n    }\n    \n    public int[] sumPrefixScores(String[] words) {\n        int n=words.length;\n        int[] ans=new int[n];\n        \n        for(int i=0;i<n;i++){\n            insert(words[i]);\n        }\n        \n        for(int i=0;i<n;i++){\n            ans[i]=startsWith(words[i]);\n        }\n        return ans;\n    }\n}\n```\n\nBtw this is my first time solving all for questions ;)\nThanks
['Trie']