Count Ways a Banned Keyword Hides as a Subsequence in Comments
Last updated: November 29, 2026
Quick Overview
Given a comment string s and a banned keyword t, count how many distinct sets of positions in s spell t in order, which measures how many ways an obfuscated keyword could be read out of the comment.
Meta
November 29, 20260
0
0 solved
Given a comment string s and a banned keyword t, count how many distinct sets of positions in s spell t in order, which measures how many ways an obfuscated keyword could be read out of the comment.
Comes up in Meta onsites with an integrity or content moderation framing, where spammers insert junk characters between the letters of a banned word. The interviewer wants a counting DP over two prefixes and a correct 1D reduction that iterates in the right direction.
What the Interviewer Expects
- Define ways[i][j] as matches of t[:j] inside s[:i]
- Split on whether s[i-1] is used to match t[j-1]
- Set the base case ways[i][0] = 1
- Reduce to one array iterating j from right to left
- Discuss overflow or modulus in fixed-width languages
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
- Why must the 1D loop go right to left?
- How would you count occurrences where at most g junk characters sit between consecutive keyword letters?
- How would you scale this to scanning millions of comments for thousands of keywords?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs are strings s (length up to 1000) and t (length up to 1000). Return the number of index sequences i1 < i2 < ... < ik with s[i1] s[i2] ... s[ik] == t. If t is empty the answer is 1 (ch...
High-Level Design
Let ways[i][j] count the ways t[:j] appears as a subsequence of s[:i]. Every way either ignores s[i-1], giving ways[i-1][j], or, when s[i-1] == t[j-1], uses it as the last matched letter, ...