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
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
tries
multi-pattern matching
string scanning
content moderation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported