Mask Banned Words in Live Comments Using a Trie
Last updated: November 29, 2026
Quick Overview
Given a live stream comment and a list of banned words, replace every character covered by any case-insensitive occurrence of a banned word with `*`, including overlapping occurrences. Return the masked comment with its original casing elsewhere.
TikTok
November 29, 20260
0
0 solved
Given a live stream comment and a list of banned words, replace every character covered by any case-insensitive occurrence of a banned word with `*`, including overlapping occurrences. Return the masked comment with its original casing elsewhere.
TikTok LIVE moderation filters comments in real time before they appear on screen, and this question tests whether you can match many patterns at once efficiently. Interviewers look for a trie walk from each start position, correct handling of overlaps, and awareness of the jump to Aho-Corasick when the banned list is large.
What the Interviewer Expects
- Builds a trie of lowercased banned words instead of checking each word at each position
- Masks the longest match from each start and handles overlapping matches
- Preserves original characters outside matches
- States complexity in terms of comment length and longest banned word
- Mentions Aho-Corasick as the linear-time upgrade
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 you avoid flagging innocent words that contain a banned substring?
- How would you catch evasion like spacing, repeated letters or leetspeak?
- The banned list has 200k entries and updates hourly; how do you deploy it to LIVE servers?
- How would you implement Aho-Corasick here and what does it change?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a comment (arbitrary Unicode, any case) and a banned word list. Matching is substring, case-insensitive. Any character inside at least one match becomes *. Overlaps must be fully covered: ban...
High-Level Design
Build a character trie from lowercased banned words, with a terminal marker. For each start index i, walk the trie along the lowercased comment and record the farthest end where a terminal node was ...