✅✅ Very easy solution beat 100% time complexity🔥🔥
Intuition:
The problem revolves around identifying words in a list (words) that start with a given prefix (pref).
The simplest method is to directly compare the
Intuition:
The problem revolves around identifying words in a list (words) that start with a given prefix (pref).
The simplest method is to directly compare the starting segment of each word with pref.
Since the prefix length is fixed and known, the task reduces to extracting the first len characters of each word and checking for equality.

Using substr allows us to neatly extract the prefix of each word for comparison. If they match, we increment a counter.

Approach:

First, determine the length of the prefix pref using pref.size().
Initialize a counter variable (count) to zero.
Iterate through the list of words (words):
For each word, extract its prefix of length len using substr(0, len).
Compare this extracted prefix with pref.
If they are equal, increment the counter.
After completing the loop, return the value of the counter as the result.
Complexity:

Time Complexity:
The substr function runs in O(m), where 𝑚  is the length of the prefix.
Iterating through all n words in the list results in a time complexity of O(n).Combining these, the overall time complexity is O(n⋅m), where:𝑛
n = number of words.
𝑚
m = length of the prefix.

Space Complexity:
No additional data structures are used aside from the counter and the loop variable.
The function operates in O(1) auxiliary space.

![Screenshot 2025-01-09 094525.png](https://assets.leetcode.com/users/images/02ac5ae0-183b-4a62-9834-3826ec8d12f5_1736396298.2145996.png)

# Code
```cpp []
class Solution {
public:
    int prefixCount(vector<string>& words, string pref) {
        
        int count=0;
        int len=pref.size();

        for(int i=0;i<words.size();i++)
        {
            if(words[i].substr(0,len)==pref)
            {
                count++;
            }
        }


        return count;
    }
};
```

![Screenshot 2024-11-06 113013.png](https://assets.leetcode.com/users/images/96732648-b871-44b7-824a-3ea8b7083981_1736396344.1814322.png)

['String', 'C++']