Count Watchlist Keywords Appearing as Subsequences of a Caption

Last updated: November 29, 2026

Quick Overview

Given a long caption string and a list of keywords, return how many keywords (counting duplicates) appear in the caption as subsequences, meaning their letters occur in order but not necessarily contiguously.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a long caption string and a list of keywords, return how many keywords (counting duplicates) appear in the caption as subsequences, meaning their letters occur in order but not necessarily contiguously.

Integrity teams look for evasive spellings where a word is spread across a caption, and this question tests efficient many-pattern subsequence checking. The interviewer wants you to avoid rescanning the caption once per keyword.

What the Interviewer Expects
  • Start from the O(|caption| * keywords) baseline and explain its cost
  • Bucket keywords by the next character they are waiting for
  • Advance every waiting keyword in a single caption pass
  • Count duplicates correctly
  • Mention the next-occurrence table plus binary search alternative
Key Topics to Cover
subsequence
bucketing
iterators
string matching
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 report the earliest caption position where each keyword completes?
  • How would precomputed next-character tables help if captions are reused?
  • What if keywords must appear within a window of length W?
  • How would you handle Unicode or emoji?
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
  • Caption length up to ~5*10^4, up to ~5,000 keywords of length up to 50, all lowercase.
  • Duplicated keywords each count.
  • Output: the count of keywords that are subsequences....
High-Level Design

Instead of scanning the caption per keyword, scan it once. Keep waiting[c], a list of iterators for keywords whose next needed character is c. Initially each keyword waits on its first character. ...


Submit Your Answer
Markdown supported