Batched Subsequence Word Matches
Problem statement
Given a lowercase swipe string swipe and an array words, return every word that is a subsequence of swipe.
A subsequence keeps character order but may skip characters. Preserve input order and repeated word occurrences. The empty word is a subsequence of every string.
Function
matchingSubsequenceWords(swipe: String, words: String[]) → String[]Examples
Example 1
swipe = "abcde"words = ["ace","aec","bd"]return = ["ace","bd"]ace and bd preserve their character order in the swipe string, while aec does not.
Example 2
swipe = "aabbcc"words = ["abc","aac","acb","abc"]return = ["abc","aac","abc"]Both occurrences of abc are preserved. acb reverses the final two required positions.
Example 3
swipe = ""words = ["","a"]return = [""]Only the empty word is a subsequence of the empty swipe string.
Constraints
0 <= swipe.length <= 200000.0 <= words.length <= 100000.- The total length of all words is at most
1000000. - All strings contain only lowercase English letters.