Flag a Character Stream When It Ends With a Blocked Term
Last updated: November 29, 2026
Quick Overview
Characters arrive one at a time from a chat stream; after each character, report whether some suffix of the stream so far equals a word in a fixed blocklist.
0
0
0 solved
Characters arrive one at a time from a chat stream; after each character, report whether some suffix of the stream so far equals a word in a fixed blocklist.
A Google onsite coding question with a trust and safety flavor, for example live filtering of YouTube chat. The interviewer is looking for the insight of storing reversed words and walking backward from the newest character, and for a bounded buffer.
What the Interviewer Expects
- Notice that only suffixes ending at the newest character matter
- Build a trie of reversed blocklist words
- Keep only the last maxLen characters in a deque
- Stop the backward walk at the first terminal node or missing child
- Compare with Aho-Corasick and explain when each wins
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would Aho-Corasick change the per-character cost?
- How would you report which word matched?
- How would you handle case folding and look-alike Unicode characters?
- How would you shard this across many chat channels?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Constructor takes words, a list of lowercase strings. query(ch) appends one character and returns True if any word equals a suffix of all characters received so far. Memory should not grow with th...
High-Level Design
After each character, the only new candidates for a match are suffixes that end at that character. Reading those suffixes from right to left means reading the newest character first, so store each blo...