Missing Words
Updated
Problem statement
You are given two sentences, s and t. Sentence t is guaranteed to be a word subsequence of s: its words occur in s in the same order, but they do not need to be consecutive.
Return the words from s that are omitted from t, preserving their order and spelling. Word matching is case-sensitive, and a hyphen is part of a word.
When repeated words allow several possible alignments, match each successive word of t to its earliest available equal word in s after the previous match. Return the words not used by that alignment.
Each sentence contains at least one nonempty word. Consecutive words are separated by one space, with no leading or trailing spaces. If every word is retained, return an empty array.
Function
missingWords(s: String, t: String) → String[]Examples
Example 1
s = "I like cheese"t = "like"return = ["I","cheese"]The word like is retained. The words before and after it are omitted, so they appear in that order.
Example 2
s = "a b a"t = "a"return = ["b","a"]The retained word matches the first a. The remaining words are b and the later a.
Example 3
s = "Build build tools"t = "build"return = ["Build","tools"]Matching is case-sensitive, so Build is not the retained lowercase word.
Example 4
s = "I am using HackerRank to improve programming"t = "am HackerRank to improve"return = ["I","using","programming"]The retained words are am, HackerRank, to, and improve. The omitted words are I, using, and programming, in that order.
Constraints
1 <= t.length <= s.length <= 10^6- Each word has length from
1through15. - Words contain only English letters and hyphens. Sentences use single spaces as separators.
tis a word subsequence ofs.
More Vanguard Online Assessment questions
- Two SumOA · Seen Sep 2026
- Valid ParenthesesOA · Seen Sep 2026
- Are They PangramsOA · Seen Nov 2025
- Spam DetectionOA · Seen Nov 2025
- Binge WatchingOA · Seen Jan 2023
- Minimum Moves Around a Circular ArrayOA · Seen Aug 2022
- Maximum Occurring CharacterOA · Seen Mar 2022
- Picking TicketsOA · Seen Mar 2022
- Tool List: Two Smallest ValuesOA · Seen Nov 2021
- Group AnagramsOA · Seen Nov 2019
Similar questions at other companies
- Minimum Swaps to Make PalindromeAmazon · OA
- Smallest Merge of Two StringsCapital One · OACapital One interview questions
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
- Palindrome After At Most One DeletionAdobe · PHONE SCREENAdobe interview questions
- Shortest Way to Form a Target StringPinterest · PHONE SCREENPinterest interview questions
- Wildcard Matching with StarsConfluent · PHONE SCREENConfluent interview questions
- Text Pattern Matching with StarsHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions