Shortest Watch History Window Containing a Playlist in Order
Last updated: November 29, 2026
Quick Overview
Given a user's YouTube watch history as a string of video codes and a playlist string, return the shortest contiguous window of the history that contains the playlist as a subsequence (in order). Return the leftmost one if tied, or an empty string.
0
0
0 solved
Given a user's YouTube watch history as a string of video codes and a playlist string, return the shortest contiguous window of the history that contains the playlist as a subsequence (in order). Return the leftmost one if tied, or an empty string.
A Google onsite Hard problem that is easy to confuse with minimum window substring, but order matters here. The interviewer checks a forward scan to find a match end and a backward scan to tighten the start, and whether the candidate can explain the complexity.
What the Interviewer Expects
- Distinguishes subsequence-in-order from multiset containment
- Scans forward to find where the playlist is completed
- Scans backward from that end to find the tightest start
- Restarts the forward scan from just after the tight start
- States O(n * m) worst case and compares with a DP solution
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
- Give the O(n * m) DP formulation.
- How would you speed this up with next-occurrence tables?
- What if you need the count of all minimal windows?
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
hist(length n) andplay(length m). - Output: the shortest substring of
histthat hasplayas a subsequence; leftmost on ties;""if none....
High-Level Design
Forward pass: from position i, walk hist matching play greedily until the last playlist character is matched at index end. This gives the earliest possible end for a window starting at or afte...