Very Easy Detailed Solution 🔥  || 🔥 Beats 100% || 🎯 Two Approaches
Approach 1:

Helper Function (isPrefix):

Checks if a string (str1) starts with another string (pref) by comparing the substring of str1 of length equal to pref
# Approach 1:
<!-- Describe your approach to solving the problem. -->
1. **Helper Function (isPrefix):**
    - Checks if a string (str1) starts with another string (pref) by comparing the substring of str1 of length equal to pref.
    - If the length of str1 is less than the length of pref, it immediately returns false since pref cannot be a prefix.

2. **Main Function (prefixCount):**
    - Iterates through the words array.
    - For each word, it calls the isPrefix function to check if the word starts with pref.
    - If isPrefix returns true, the counter ans is incremented.

3. **Return Value:**
    - The total count of words with the specified prefix is returned.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$O(n*n2)$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$O(n*n2)$
# Code
```java []
class Solution {
    private boolean isPrefix(String str1, String pref) {
        int n1 = str1.length(), n2 = pref.length();
        if (n1 < n2) {
            return false;
        }
        return str1.substring(0, n2).equals(pref);
    }
    public int prefixCount(String[] words, String pref) {
        int n = words.length, ans = 0;
        for(int i=0; i<n; i++){
            if(isPrefix(words[i], pref)){
                ans++;
            }
        }
        return ans;
    }
}
```

# Approach 2 : Optimized
<!-- Describe your approach to solving the problem. -->
1. **Loop Through the Words:**
    - Iterate through each string in the words array.

2. **Length Check:**
    - If the length of the current string (s) is less than the length of pref, it cannot have pref as a prefix, so mark it with flag = false.

3. **Character-by-Character Comparison:**
    - If the length is sufficient, compare characters of the word and the prefix one by one up to the length of pref.
    - If any character doesn't match, set flag = false and break out of the inner loop.

4. **Count Matching Prefixes:**
    - If flag remains true, increment the counter ans.

5. **Return the Count:**
    - Finally, return the total count of words that match the prefix.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$O(n*m)$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$O(1)$
# Code
```java []
class Solution {
    public int prefixCount(String[] words, String pref) {
        int n = words.length;
        int m = pref.length();
        int ans = 0;
        for(int i=0; i<n; i++){
            String s = words[i];
            boolean flag = true;
            if(s.length() < m){
                flag = false;
            }
            else{
                for(int j=0; j<s.length() && j<m; j++){
                    if(s.charAt(j) != pref.charAt(j)){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag){
                ans++;
            }
        }
        return ans;
    }
}
```
['Array', 'String', 'String Matching', 'Counting', 'Java']