Easy and 100% fast solution using string method
IntuitionTo solve the problem of finding how many strings in the words array are a prefix of string s, let us break this problem :-

Understanding a Prefix :-
![image.png](https://assets.leetcode.com/users/images/efecd940-e574-42ad-8225-84689f70f6c2_1734427968.1863089.png)\n\n# Intuition\nTo solve the problem of finding how many strings in the `words` array are a prefix of string `s`, let us break this problem :-\n1. **Understanding a Prefix** :-  A string w is said to be a prefix of another string `s` if `w` matches the starting part of `s`. FOr example :-\n    - `"app"` is a prefix of `"apple"`.\n    \n2. **Matching Prefixes** :- Compare each `word` in `words` to the start of `s` to check if it forms a prefix.\n\n3. **Efficient Comparison** :- Loop through all `words` in the words array.\n\n# Approach\n1. Initialize a `counter` variable to keep track of how many `words` are prefixes of `s`.\n2. Loop through each word in the words array.\n3. Use the `startsWith()` method to check if the current `word` is a prefix of `s`.\n4. If it is, increment the counter.\n5. Return the `counter` after checking all the words.\n\n\n# Complexity\n- **Time complexity** :- Let `n` be the number of `words` in the words array, and `m` be the average length of words. For each `word`, startsWith() takes `O(m)` time to compare. So, total time complexity will be `O(n\xD7m)`and as `m` is very small (10). Hence this can be written as `O(n)` time complexity\n\n- **Space complexity** :- `O(1)` as we are not using any additional data structures apart from the counter variable.\n\n# Code\n``` JavaScript []\nlet countPrefixes = function(words, s) {\n    // using the reduce() method to accumulate the count of valid prefixes\n    return words.reduce((prefixCount, currWord) => {\n        // check if \'s\' starts with the current word using startsWith()\n        // \'s.startsWith(currentWord)\' returns true (1) if currentWord is a prefix, otherwise false (0)\n        return prefixCount + s.startsWith(currWord);\n    }, 0);  //initialize prefixCount (accumulator) to 0\n};\n```\n``` Java []\nclass Solution {\n    public int countPrefixes(String[] words, String s) {\n        // initialize the prefix count `prefixCount` to 0\n        int prefixCount = 0;\n\n        // iterate through each word in the \'words\' array\n        for(String word : words){\n            // check if the current word is a prefix of \'s\'\n            if(s.startsWith(word)){\n                prefixCount++;\n            }\n        }\n\n        // return the total count of prefixes\n        return prefixCount;\n    }\n}\n```\n```cpp []\nclass Solution {\npublic:\n    int countPrefixes(vector<string>& words, string s) {\n    // initialize the prefix count `prefixCount` to 0\n    int prefixCount = 0;\n\n    // iterate through each word in the \'words\' array\n    for (string word : words) {\n        // check if the current word is a prefix of \'s\'\n        if (s.substr(0, word.size()) == word) {\n            prefixCount++;\n        }\n    }\n\n    // return the total count of prefixes\n    return prefixCount;\n}\n};\n```
['Array', 'String', 'C++', 'Java', 'JavaScript']