FastPrepStreaming Inference Stop Sequence Detection
Problems/Streaming Inference Stop Sequence Detection

Streaming Inference Stop Sequence Detection

Microsoft logoMicrosoft● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft onsite interview. The report asks for detecting stop tokens while a model generates text, but does not give the interface or the exact matching rules. Here, the text comes in chunks, stops can be several characters long, and we set the rules for finishing and for ties, and the input limits. Our version is about 75% the same as the reported question.

An inference stream arrives as an ordered array of text chunks. Detect the configured nonempty stopSequences while consuming the characters in order, and return the generated text before the selected stop.

  • Matching is case-sensitive. A stop may span any number of chunks, and empty chunks do not reset matching state.
  • Stop immediately when any stop sequence finishes. If several finish on the same character, choose the longest one, which starts earliest.
  • Exclude the entire selected stop and ignore all later characters.
  • If no stop completes, return all input text, including an unfinished stop prefix at the end. An empty stop list never stops the stream.

This exercise uses text stop sequences, including multi-character markers such as <END>.

Function

truncateAtStop(chunks: String[], stopSequences: String[]) → String

Examples

Example 1

chunks = ["Hello <EN","D>ignored"]stopSequences = ["<END>"]return = "Hello "

The stop sequence spans the two chunks and is excluded from the returned text.

Example 2

chunks = ["abcd"]stopSequences = ["abcd","bc"]return = "a"

bc completes after c, before the longer abcd stop can complete. Detection uses the earliest completion, not the earliest start.

Example 3

chunks = ["x","abc"]stopSequences = ["bc","abc"]return = "x"

Both stops complete on c. The longer abc begins earlier, so it is the selected stop.

Constraints

  • 0 <= chunks.length <= 1000; total chunk length is at most 100000.
  • 0 <= stopSequences.length <= 200.
  • Every stop has length between 1 and 200, and their total length is at most 4000.
  • All characters are printable ASCII, with codes from 32 through 126.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Concatenated WordsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Extract Company Tickers from NewsSusquehanna International Group (SIG) · ONSITE INTERVIEWSusquehanna International Group (SIG) interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Longest Word Containing Another InputMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Word Search IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Word Break IIGoogle · ONSITE INTERVIEWGoogle interview questions
  • Word SquaresInMobi · ONSITE INTERVIEWInMobi interview questions
  • Check Each Word in a Character GridZillow · ONSITE INTERVIEWZillow interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String truncateAtStop(String[] chunks, String[] stopSequences) {
        // Write your code here
    }
}
Checking account…