Dictionary Matches from Repeated Letters
Problem statement
The string typed was formed by taking a word and repeating each character one or more consecutive times. For every word in dictionary, determine whether deleting only extra copies inside runs of typed can produce that word.
Return matching dictionary entries in their original order. Duplicates in the dictionary remain duplicated.
Function
expandedWordMatches(typed: String, dictionary: String[]) → String[]Examples
Example 1
typed = "heellp"dictionary = ["help","heelp","hello"]return = ["help","heelp"]Each matching run uses no more copies than typed provides.
Example 2
typed = "aaabb"dictionary = ["ab","aab","aaabb","abbc"]return = ["ab","aab","aaabb"]The a and b run counts may independently shrink but not vanish.
Example 3
typed = "abc"dictionary = ["abc","abbc","ac"]return = ["abc"]No run has an extra copy to remove.
Constraints
1 <= typed.length <= 10^5.- The total dictionary character count is at most
2 * 10^5. - All strings contain lowercase English letters.