NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

An AI model's output arrives as a stream of text chunks: an ordered list of strings, stream. The stream contains a stop token, the literal string "<END>", marking where the meaningful output ends. In this part, the stop token always appears fully inside a single chunk.

Return only the chunks that come before the stop token, following these rules:

  • Each input chunk maps to at most one output chunk. The original chunk boundaries are preserved.
  • Chunks before the stop token are kept as-is, including empty chunks.
  • The chunk that contains the stop token contributes only the text before it. If that text is empty, the chunk is skipped.
  • Everything from the stop token onward, and every chunk after it is discarded.
  • If the stop token never appears, return all chunks unchanged.

Constraints:

  • The stop token has length 5.
  • 0 ≤ stream.size() ≤ 10410^4
  • 0 ≤ stream.get(i).length() ≤ 10410^4
  • All strings are non-null.

Constraints:

  • The stop token is the fixed literal string <END> (length 5); matching is case-sensitive.
  • 0 ≤ stream.size() ≤ 10410^4
  • 0 ≤ stream.get(i).length() ≤ 10410^4
  • All strings are non-null.

Example 1:

Input: stream = ["hello", "how are you<END>", "HAPPY"] Output: ["hello", "how are you"] Explanation:

  • The first chunk "hello" contains no stop token, so it is emitted unchanged.
  • The second chunk "how are you<END>" contains the stop token <END>; only the text before it, "how are you", is emitted, and everything from <END> onward is discarded.
  • The third chunk "HAPPY" comes after the stop token and is dropped entirely.

Example 2:

Input: stream = ["", "keep", "<END>drop", "later"] Output: ["", "keep"]

Example 3:

Input: stream = ["alpha", "", "beta"] Output: ["alpha", "", "beta"]


Accepted
246/498
Acceptance Rate49.4%
Test Cases
Input
stream =
Output
Expected