cswork / OA打开练习工作台

SuperhumanOA #1

Lost Messages

估计简单评测数据准备中,可先阅读题面

考点(AI 标注)双指针滑窗字符串

A message is represented as a string of space-delimited words. You are given two strings:

  • sent: the original message
  • received: the message that was recovered after transmission Some words may be missing from received. It is guaranteed that all words in received appear in the same relative order as they do in sent. Return all words that appear in sent but do not appear in received, preserving their original order. Function Description Complete the function lostFragments in the editor below. lostFragments has the following parameters:
  • String sent: the original message that was sent
  • String received: the recovered message after transmission Returns String[]: the words from sent that are missing from received, in the order they appear in sent

Constraints

  • sent and received contain only lowercase or uppercase English letters and spaces.
  • Words are separated by single spaces.
  • 1 ≤ received.length() < sent.length() ≤ 10⁵
  • The length of any individual word in sent or received is at most 15.
  • received is guaranteed to be a subsequence of sent at the word level.

Example 1

Input:

sent = "I am a programmer"
received = "I programmer"

Output:

["am", "a"]

Explanation: The words "am" and "a" appear in sent but are missing from received, so they are returned in order.

Example 2

Input:

sent = "we love coding daily"
received = "we coding"

Output:

["love", "daily"]

Explanation: The recovered message keeps "we" and "coding" in order, so the missing words are "love" and "daily".

Example 3

Input:

sent = "alpha beta gamma delta"
received = "alpha delta"

Output:

["beta", "gamma"]

Explanation: The recovered message is a subsequence of the sent message. The missing words between the matched endpoints are returned.