[C++] Detailed Explanation w/ Diagram | Easy and commented code | Simple language
IDEA:\n We store each word of the words array in the trie.\n Every Node of the trie contains two arrays of size 26.\n First array denotes the characters of engl
**IDEA:**\n* We store each word of the words array in the trie.\n* Every Node of the trie contains two arrays of size 26.\n* First array denotes the characters of english alphabets i.e index 0 denotes character \'a\', index 1 denotes character \'b\'... like this.\n* Second array number denotes how many number of times we visited here.\n* Lastly we simply traverse each word and take out the answer.\n* See images for better clarification.\n___________\n![image](https://assets.leetcode.com/users/images/771e005c-2162-4047-ba3a-35ff6299f9d5_1663486810.0475035.jpeg)\n![image](https://assets.leetcode.com/users/images/3146ce46-1250-40c7-9c7f-e29df6a531dc_1663486839.4647455.jpeg)\n___________\n```\nSee commented code :)\n```\n____\n**C++**\n```\n// how a trie node looks like\nstruct Node \n{\n    Node* links[26]; // for 26 characters\n    int number[26] = {0}; // number array \n    \n    bool containsKey(char ch) // function to check if it present or not\n    {\n        return (links[ch - \'a\'] != NULL);\n    }\n    \n    void put(char ch, Node* node) \n    {\n        links[ch - \'a\'] = node; // put a character\n        number[ch - \'a\'] = 1; // since we are putting this character, so we visit this character first time\n    }\n    \n    Node* get(char ch) // make a link to the character\n    {\n        return links[ch - \'a\'];\n    }\n    \n    void increaseNum(char ch) // we increase the count of visit\n    {\n        number[ch - \'a\']++;\n    }\n    \n    int getNum(char ch) // to retrive how many many number of times we visit this\n    {\n        return number[ch - \'a\'];\n    }\n    \n};\n\nclass Trie {\npublic:\n    Node* root; // make root node\n    Trie() {\n        root = new Node(); // accquiring memory for the root node\n        \n    }\n    \n    void insert(string word) \n    {\n        Node* node = root; // make a dummy pointer for the root node\n        \n        for(int i = 0; i < word.length(); i++)\n        {\n            // if on the node i m currently standing does \n            // not contain this particular character of word[i]\n            // so for this we have to make a new referenced node\n            if(!node -> containsKey(word[i]))\n            {\n                node -> put(word[i], new Node());\n            } \n            else // else if already present that means we see this character again so increase nums\n             node -> increaseNum(word[i]);\n            \n            // after this move to this referenced node\n            node = node -> get(word[i]);\n        }\n    }\n    \n    // it will give me answer for each word\n    int takeAns(string word)\n    {\n        int ans = 0; // to count my answer\n        \n        Node* node = root; // make a dummy pointer for the root node\n        \n        for(int i = 0; i < word.size(); i++)\n        {\n            if(!node -> containsKey(word[i]))  // if trie does not contain this particular character, so return answer from here\n                return ans;\n            else \n                ans += node -> getNum(word[i]); // else add to answer\n            \n             node = node -> get(word[i]); // and move to next referenced node\n        }\n        \n        return ans; // finally return answer\n    }\n};\n\nclass Solution {\npublic:\n    vector<int> sumPrefixScores(vector<string>& words) {\n        int n = words.size(); // extract size of words array\n        \n        Trie trie; // define object for class trie\n        \n        // put all strings of words array into the trie\n        for(int i = 0; i < n; i++)\n        {\n            trie.insert(words[i]);\n        }\n        \n        vector<int> ans(n); // vector that contains my answer\n \n        // extract answer for each word\n        for(int i = 0; i < n; i++)\n        {\n            ans[i] = trie.takeAns(words[i]);\n        }\n        \n        return ans; // finally return answer\n    }\n};\n```
['C']