How would you solve stop word detection in stream?
I recently failed on this interview question:
Part 1:
Given a string and a list of stopwords, return the substring that appears before the first occurrence of any stopword.
Part 2:
What if the input is a stream and cannot be fully loaded into memory?
Example:
stopWords = ["<end>", "<stop>", "/n"]
stream = Iterable(["Hello ", "world<st", "op>Welcome back"])
Expected output:
Iterable(["Assume ", "the world is great"])
I managed part 1 but couldn't get a solid solution for part 2. Tried a sliding buffer approach where I only have the maxStopWord length in memory, but I couldn't get the output chunks match the example.
Posted Jul 8, 2025, 4:41 PM UTC
15