Shortest Clip Containing a Keyword Sequence as a Subsequence
Last updated: November 29, 2026
Quick Overview
Given a video transcript string s and a keyword pattern t, return the shortest substring of s that contains t as a subsequence (characters in order, not necessarily adjacent). If several tie, return the leftmost; if none, return an empty string.
Meta
November 29, 20260
0
0 solved
Given a video transcript string s and a keyword pattern t, return the shortest substring of s that contains t as a subsequence (characters in order, not necessarily adjacent). If several tie, return the leftmost; if none, return an empty string.
A Hard two pointer problem framed around extracting the tightest clip from a Reels transcript. Meta interviewers use it to see if you can design a forward scan to find a valid end and a backward scan to tighten the start.
What the Interviewer Expects
- Distinguishes subsequence containment from the anagram-style window problem
- Scans forward to find the earliest end where t is fully matched
- Scans backward from that end to find the latest valid start
- Restarts the forward scan just after that start
- Gives O(|s| * |t|) time and mentions a DP or next-occurrence table alternative
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
- Precompute a next-occurrence table and analyze the new complexity.
- Return all minimal windows instead of the leftmost shortest one.
- Allow up to one character of t to be skipped.
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: strings s (up to 2 * 10^4) and t (up to 100). Output: the shortest substring of s in which t appears as a subsequence, leftmost on ties, or ""....
High-Level Design
Start a forward pointer at i. Advance through s, matching characters of t in order, until all of t is matched at some end index e. That gives the earliest window end for this start region. T...