Count Prefixes of a Given String (Optimal Approach)
IntuitionApproachGo through the array and check if the each element starting matches the prefix word.Complexity
Time complexity:
O(n)
Space complexity:
O(1)Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
Go through the array and check if the each element starting matches the prefix word.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)

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

# Code
```cpp []
class Solution {
public:
    int countPrefixes(vector<string>& words, string s) {
        int count=0;
        for(string val:words){
            if(s.find(val)==0) count++;
        }
        return count;
    }
};
```
['Array', 'String', 'C++']