FastPrepMissing Words

Missing Words

Airbnb logoAirbnb● EasyFULLTIMEOA
Learn

Problem statement

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.

More Airbnb problems

See Airbnb hiring insights
public List<String> missingWords(String s, String t) {
    // Write your code here.
}
s"I am using HackerRank to improve programming"
t"am HackerRank to improve"
expected["I", "using", "programming"]
Checking account…