Count how many words in a list start with a given prefix.
You are given a list of words and a prefix string. Return how many words begin with that prefix.
A word is considered a match if the prefix appears at the start of the word exactly, character by character.
Write a function that counts the matching words efficiently and returns the total number of matches.
wordspref representing the prefix to matchwords that start with pref1 <= words.lengthExample 1
Input
words = ["pay", "attention", "practice", "attend"], pref = "at"
Output
2
Explanation
"attention" and "attend" start with "at".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.