Shortest Feed Window Containing Every Required Campaign Hashtag
Last updated: November 29, 2026
Quick Overview
Each video in a user's feed carries a list of hashtags. Given the feed in order and a set of required campaign hashtags, return the shortest contiguous range of videos that together cover every required hashtag, or an empty result if none exists.
TikTok
November 29, 20260
0
0 solved
Each video in a user's feed carries a list of hashtags. Given the feed in order and a set of required campaign hashtags, return the shortest contiguous range of videos that together cover every required hashtag, or an empty result if none exists.
TikTok ads and brand campaign teams care about how quickly a user is exposed to all assets of a campaign, which makes this a natural onsite variant of the minimum window problem. The interviewer checks whether you can generalize the classic substring version to items that carry multiple tags and still keep the counting correct.
What the Interviewer Expects
- Tracks per-hashtag counts inside the window and a counter of how many required tags are currently satisfied
- Handles videos with several hashtags, including repeats and irrelevant tags
- Shrinks from the left while the window still covers everything, updating the best answer
- Returns indices, and handles the no-solution case
- Achieves O(total tags) time
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
- What if each required hashtag must appear at least twice?
- How would you support the feed arriving as an unbounded stream with a memory cap?
- How would you change this if the window is measured in seconds of watch time instead of number of videos?
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:
feed: list[list[str]](hashtags per video),required: set[str]. - Output:
(start, end)inclusive indices of the shortest window covering all required tags, orNone. - Ties: return the...
High-Level Design
This is minimum window substring, except each position contributes a bag of tags. I keep count[tag] for required tags inside the window and have, the number of required tags with count at least 1....