<Count Words with a Given Prefix in a List>
IntuitionThe problem is about counting how many words start with a given prefix. To solve this, we can simply check the beginning of each word in the list to se
# Intuition
The problem is about counting how many words start with a given prefix. To solve this, we can simply check the beginning of each word in the list to see if it matches the prefix.


<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
1)Loop through each word in the list.
2)Use the substr function to extract the prefix of the word, and compare it with the given prefix.
3)If they match, increase the count.
4)Return the total count after processing all the words.

<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:

O(n⋅k), where 
n is the number of words and 
k is the average length of the prefix.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
- O(1), as no additional space is used.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
#include <string>
#include <vector>
using namespace std;

class Solution {
public:
    int prefixCount(vector<string>& words, string pref) {
        int count = 0;
        for (const string& word : words) {
            if (word.substr(0, pref.size()) == pref) {
                count++;
            }
        }
        return count;
    }
};

```
['C++']