Flag a Live Comment Stream When It Ends With a Banned Word
Last updated: November 29, 2026
Quick Overview
Build a checker that receives the characters of a live comment one at a time and, after each character, returns True if the text received so far ends with any word from a fixed banned list.
Meta
November 29, 20260
0
0 solved
Build a checker that receives the characters of a live comment one at a time and, after each character, returns True if the text received so far ends with any word from a fixed banned list.
Facebook Live and Instagram Live surface comments in real time, and integrity checks need to fire as text streams in rather than after a full scan. The interviewer is checking whether you see that suffix queries become prefix queries on a trie of reversed words, and that memory per stream can be bounded.
What the Interviewer Expects
- Recognize this as a suffix match on a growing stream
- Build a trie of reversed banned words
- Walk backwards from the newest character and stop at the first end marker
- Cap the stored buffer at the longest banned word length
- Compare against Aho-Corasick for multi-pattern streaming
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 give O(1) amortized per character?
- How would you handle case and leetspeak substitutions?
- How would you serve millions of concurrent streams?
- What if the banned list updates while streams are open?
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 gets the banned list (lowercase letters).
query(ch)appends one character and returns whether any banned word is a suffix of the stream.- Per-stream memory should not grow without b...
High-Level Design
A banned word is a suffix of the stream exactly when its reverse is a prefix of the reversed stream. So insert each banned word reversed into a trie. Keep a deque of the most recent characters, ca...