🔍 Count Prefixes in a String – Clean and Concise Python Solution!🚀
🧠 Intuition💡 The task is to count how many words in the list words are prefixes of the string s.
A word is a prefix of s if it matches the initial characters of
![image.png](https://assets.leetcode.com/users/images/dd38a7eb-9c88-4ea0-8600-d38945a43464_1736404286.578581.png)



# 🧠 **Intuition**  
💡 The task is to count how many words in the list `words` are prefixes of the string `s`.  
- A word is a prefix of `s` if it matches the initial characters of `s`.  
- We can check this by slicing `s` up to the length of the word and comparing it with the word.  

---

# 🔍 **Approach**  
1️⃣ Initialize a counter `cnt` to keep track of the number of prefix matches.  
2️⃣ Iterate through each word in `words`.  
3️⃣ For each word, check if it matches the prefix of `s` (using slicing).  
4️⃣ If it matches, increment the counter.  
5️⃣ Return the final count after checking all words.  

---

# ⏱️ **Complexity**  
- **Time Complexity**: $$O(n \cdot m)$$  
   - **n**: Number of words in the list.  
   - **m**: Average length of the words.  
- **Space Complexity**: $$O(1)$$  
   - No extra space is used beyond a few variables.

---

# 💻 **Code**  
```python
class Solution:
    def countPrefixes(self, words: List[str], s: str) -> int:
        cnt = 0  # 🔢 Initialize counter
        for word in words:
            # ⚡ Check if the word is a prefix of s
            if s[:len(word)] == word:
                cnt += 1  # ✅ Increment count for a match
        return cnt  # 🔙 Return the total count
```

---

### 🌟 **Example Walkthrough**  
```python
words = ["a", "b", "c", "ab", "abc"]
s = "abc"
solution = Solution()
print(solution.countPrefixes(words, s))  # Output: 3 🚀
```

---

### 🔥 **Like this solution? Let’s keep solving awesome problems together!** 🌟
['Python3']