C# Solution for Counting Words With a Given Prefix Problem
IntuitionThe problem is about counting the number of words in the array words that start with a given prefix pref. A prefix is a contiguous substring starting f
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem is about counting the number of words in the array words that start with a given prefix pref. A prefix is a contiguous substring starting from the first character of a word. In C#, the StartsWith method provides a straightforward way to check if a string begins with a specified substring, so the solution relies on iterating through the array and applying this method to each word.

# Approach
<!-- Describe your approach to solving the problem. -->
1.	Initialize a Counter:
	•	Create a variable count to keep track of the number of words that match the prefix.
2.	Iterate Through the words Array:
	•	Use a foreach loop to traverse each word in the array.
	•	For each word, use the StartsWith method to check if the word starts with pref.
3.	Update the Counter:
	•	If word.StartsWith(pref) returns true, increment the count.
4.	Return the Count:
	•	After iterating through all the words, return the final value of count.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n * m), where:
	•	 n : The number of words in the array (words.Length).
	•	 m : The maximum length of a word or the prefix (Math.Min(word.Length, pref.Length) for each comparison).

Explanation:
	•	For each word in the words array, the StartsWith method compares the characters of the prefix pref with the beginning of the word, which takes  O(m) .
	•	Since the loop iterates through  n  words, the total time complexity is  O(n x m) .

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

Explanation:
	•	The solution uses a constant amount of extra space for variables like count and loop iterators.
	•	The StartsWith method does not require additional memory.

# Code
```csharp []
public class Solution {
    public int PrefixCount(string[] words, string pref) {
        int count = 0; 
        foreach (string word in words) {
            if (word.StartsWith(pref)) {
                count++; 
            }
        }

        return count;
    }
}
```
['C#']