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
Coding & Algorithms
Machine Learning Engineer
Meta
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Hard

0

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
two pointers
subsequence
forward and backward scan
string windows
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported