Eassyyy Pessyyy Solution🔥| Runtime 100% 🔥| Easy to understand ✅
IntuitionThe problem is about counting the number of words in the given list words that start with a specific prefix pref. A prefix is a substring at the beginn
![Screenshot 2025-01-09 093958.png](https://assets.leetcode.com/users/images/734c5794-bf41-4d21-a1d4-668ef448e9e8_1736396216.180397.png)

# Intuition
The problem is about counting the number of words in the given list words that start with a specific prefix pref. A prefix is a substring at the beginning of a string. For each word, we check if its starting characters match the given prefix. This requires an exact character-by-character match for the length of the prefix.

# Approach
1. Initialize a counter count to zero to keep track of the number of words starting with the prefix.
2. Iterate through each word in the input vector words:
    * Extract a substring from the beginning of the word with a length equal to the length of the prefix using substr().
    * Compare this substring with pref.
    * If they are equal, increment the counter count.
3. After iterating through all the words, return the value of count.

# Complexity
### Time Complexity: `O(n.m)`
* Let n be the number of words in the input list words and m be the average length of a word.
* The substr() operation takes O(k), where k is the length of the prefix pref.
* Comparing two strings of length m takes O(m).
* For each word, the operations take O(m), and since there are n words, the total time complexity is O(n⋅m).
### Space Complexity: `O(1)`
 * The algorithm uses constant extra space O(1) since no additional data structures are used (besides the counter and temporary substrings).


# Code
```cpp []
class Solution {
public:
    int prefixCount(vector<string>& words, string pref) {
        int count = 0;
        for(int i = 0; i < words.size(); i++ ){
            if(words[i].substr(0,pref.size()) == pref){
                count++;
            }
        }
        return count;
    }
};
```
```Java [Java]
class Solution {
    public int prefixCount(String[] words, String pref) {
        int count = 0;
        for (String word : words) {
            if (word.startsWith(pref)) {
                count++;
            }
        }
        return count;
    }
}
```
![Shinchan_upvote.jpg](https://assets.leetcode.com/users/images/de091c5e-0765-4809-93ce-0addcc8024dc_1736396253.9402227.jpeg)


['Array', 'String', 'String Matching', 'C++', 'Java']