Reported March 2019
Airbnbtwo pointers

Missing Words

Reported by candidates from Airbnb's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Airbnb OA. Under 2s to a working solution.
Founder's read

Airbnb reportedly sent this one in March 2019, and the input size is the first thing that matters. Strings run up to 10^6 characters, so anything that rescans t for every word in s is dead on arrival. The task: t is a word-level subsequence of s, and you return the words of s that t didn't consume, in order. It's a two-pointer walk dressed up as a string problem. If you've got an invite in your inbox, this is the kind of question you want to see. If your head goes blank mid-assessment, StealthCoder runs invisibly as a safety net.

The problem

You are given two sentences s and t. Each sentence contains words separated by single spaces, with no leading or trailing space. The words of t form a case-sensitive subsequence of the words of s: they appear in the same order, but they do not need to be adjacent.
Return the words of s that are missing from t, preserving their original order.

Function
missingWords(s: String, t: String) → List<String>

Examples
Example 1
s = "I am using HackerRank to improve programming"
t = "am HackerRank to improve"
return = ["I", "using", "programming"]
Matching the four words of t leaves I, using, and programming unmatched in s.
Example 2
s = "I love programming"
t = "I love programming"
return = []
Every word is matched, so no words are missing.
Example 3
s = "one two one three"
t = "one one"
return = ["two", "three"]
The two occurrences of one must be matched in order, leaving the intervening and trailing words.

Constraints
1 <= t.length() <= s.length() <= 10^6.
Both strings contain only English letters and single spaces between words.
Every word has length from 1 through 15.
The words of t are guaranteed to be a subsequence of the words of s.
Matching is case-sensitive.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a single pass with two pointers over the word arrays. Split both sentences on spaces. Walk through s with index i, and keep j pointing at the next unmatched word in t. If j is still in range and s[i] equals t[j], advance j and skip the word. Otherwise append s[i] to the result. That's O(n) time and the guarantee that t is a subsequence means you never need backtracking. The common pitfall is using a set or hash map of t's words. Example 3 breaks it: "one" appears twice in s, and only the first two matches in order count, so duplicates and position matter. Another trap is comparing case-insensitively. Matching is case-sensitive. Don't split inside a loop repeatedly either. Split once, then scan. If you freeze on the greedy matching logic during the live OA, StealthCoder is the hedge that hands you the pointer loop.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Missing Words cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Airbnb's OA.

Airbnb reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Missing Words FAQ

What's the trick for Missing Words?+

Two pointers over the split word lists. Walk s, and whenever the current word equals the next unmatched word in t, advance t's pointer and skip it. Otherwise add it to the output. One pass, no backtracking, because t is guaranteed to be a subsequence of s.

Why can't I just use a set of t's words?+

Duplicates and order. In the example s = "one two one three" and t = "one one", a set would drop both ones from s. Here that happens to work, but with s = "one one" and t = "one", the set removes both and you'd return nothing instead of ["one"]. Use pointers.

How hard is this problem really?+

Easy. The logic is a short greedy scan. The difficulty is input size, up to 10^6 characters, which punishes quadratic approaches, and getting the edge cases right, like repeated words and the case-sensitive comparison.

What's the time and space complexity?+

O(n) time where n is the total length of the strings, since you split each once and scan s once. Space is O(n) for the word arrays and the output list. Comparing words is bounded because every word is at most 15 characters.

How do I prepare for this in 48 hours?+

Practice the two-pointer subsequence pattern until it's automatic. Write it once from scratch, then test the three given examples, especially repeated words and the case where t equals s. Also check you split on a single space and handle the empty result properly.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Airbnb.

OA at Airbnb?
Invisible during screen share
Get it