Simple | Python 1 Liner | C++ 3 Liner | Beats 100%
Beats 100%IntuitionTo solve this problem, we want to count how many strings in the given list of words start with a specific prefix. The solution can utilize th
# Beats 100% 
# Intuition
To solve this problem, we want to count how many strings in the given list of words start with a specific prefix. The solution can utilize the startswith functionality or compare substrings directly for optimal performance. The task is straightforward because comparing substrings or prefixes can be done efficiently.


# Approach
- Iterate over the list of words.
- - Maintain a counter to keep track of words that satisfy the condition.
- For each word, check if it starts with the given prefix using substring, if yes, increment the counter.
- Return the final count.

# Complexity
### Time complexity:
𝑂(𝑛⋅𝑚)
- O(n⋅m), where:
- 𝑛 : n is the number of words in the list.
- 𝑚 : m is the length of the prefix.


### Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1) : as we do not use any extra space that grows with input size.

### If you found this explanation helpful, an upvote would be greatly appreciated!

# Code
```python []
class Solution(object):
    def prefixCount(self, words, pref):
        return (sum(wrd[0:len(pref)]==pref for wrd in words)) 
        
```
```cpp []
class Solution {
public:
    int prefixCount(vector<string>& words, string pref) {
        int cnt=0, l=pref.size();
        for(string word: words){ cnt += word.substr(0, l)==pref;}
        return cnt;
    }
};
```
['String', 'String Matching', 'Python']