The Expressive Words interview question involves "stretchy" words. A word is stretchy if you can take any group of identical consecutive characters and lengthen the group to 3 or more characters. For example, "hello" can be stretched to "helllooo" (3 'l's, 3 'o's) but not "hhello" (only 2 'h's). You are given a target string s and a list of words. You need to count how many words in the list can be stretched to match s.
Companies like Google and Cisco use this String coding problem to test your ability to group and compare character sequences. It evaluates whether you can effectively use Two Pointers or group-based analysis. It requires careful handling of edge cases, such as when a group in the original word is already longer than the target or when the character counts don't allow for a valid stretch.
The problem uses a Two Pointers / Run-Length Encoding pattern.
s and a word w group by group.c1 be the count in s and c2 be the count in w.c1 < c2, it's impossible (cannot shrink).c1 > c2 and c1 < 3, it's impossible (stretching must result in at least 3 chars).s = "heeellooo", words = ["hello", "hi"]
c1 >= 3 and c1 > c2. (Stretched, OK).c1 >= 3. (Stretched, OK).
Result: "hello" is valid.s.
Result: "hi" is invalid.c2 > c1, which is invalid because you can only add characters, not remove them.Whenever you process strings with repeating characters, think about "Run-Length Encoding" (representing "aaabb" as (a, 3), (b, 2)). This often simplifies the comparison logic significantly.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Sentence Similarity III | Medium | Solve | |
| Check If String Is a Prefix of Array | Easy | Solve | |
| Find First Palindromic String in the Array | Easy | Solve | |
| Shortest Distance to a Character | Easy | Solve | |
| Longest Word in Dictionary through Deleting | Medium | Solve |