Have you ever noticed how people stretch out letters when they're really excited? Like when someone types "hellooooo!" instead of just "hello", or "hiiiiii" instead of "hi"? That's exactly what this problem is about!
You're given a stretched string s and an array of normal words. Your task is to find how many of these normal words could have been stretched to create the string s.
The stretching rules are:
- You can take any group of consecutive identical letters in a word
- You can extend that group by adding more of the same letter
- But here's the catch: the final group must have at least 3 letters
Example: Starting with "hello", you could stretch the "o" to get "hellooo" (3 o's), or stretch the "ll" to get "hellllo" (4 l's), but you cannot get "helloo" because "oo" has only 2 letters.
Goal: Return the count of words that can be stretched to match the given string s.
Input & Output
Constraints
- 1 โค s.length, words[i].length โค 50
- 1 โค words.length โค 100
- s and words[i] consist of lowercase English letters only
- A group of characters can only be stretched if the result has at least 3 characters
- Groups with less than 3 characters must remain unchanged