Whole Word Muted Phrase Matching Across Many Posts
Last updated: November 29, 2026
Quick Overview
Users can mute words and phrases. Given one user's muted phrases (possibly hundreds) and a stream of posts, return which muted phrases each post contains, case-insensitive, matching only on whole-word boundaries, in time linear in the post length.
X
November 29, 20260
0
0 solved
Users can mute words and phrases. Given one user's muted phrases (possibly hundreds) and a stream of posts, return which muted phrases each post contains, case-insensitive, matching only on whole-word boundaries, in time linear in the post length.
Muted words on X are applied at read time to every timeline, notifications and search result, so naive per-phrase substring search multiplies work by the size of the mute list. The onsite expects a multi-pattern automaton (Aho-Corasick or equivalent), correct boundary checks, and discussion of Unicode and scale.
What the Interviewer Expects
- Rejects O(posts x phrases x length) naive search with reasoning
- Builds a trie with failure links
- Collects outputs through failure links so overlapping phrases are found
- Applies word boundary checks at match time
- Analyzes build and query complexity
- Mentions normalization and hashtag handling
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
- A muted word should also match its plural or hashtag form. How would you extend this?
- How would you share automata across millions of users whose mute lists overlap heavily?
- Lowercasing can change string length for some characters. Where does that break your boundaries?
- Where in the serving stack would you apply this filter, and why?
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: phrases like spoiler, game of thrones, #GOT. A phrase matches a post when it appears, ignoring case, with no letter or digit immediately before or after it, so he matches he saw but n...
High-Level Design
Build a trie of lowercased phrases. BFS from the root to set failure links: the failure of a node is the longest proper suffix of its string that is also a trie prefix. Each node's output list include...