Batched Subsequence Word Matches
Updated
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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Time Based Key-Value StoreZillow · PHONE SCREEN
- Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEW
- Highest Bid Campaign MatcherStackAdapt · ONSITE INTERVIEW
- Group AnagramsAmazon Web Services · ONSITE INTERVIEW
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEW
- File System Shell CommandsHarvey · ONSITE INTERVIEW
- Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEW
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEW
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEW