Fill a Streaming Ad Pod With Competitive Separation
Last updated: November 29, 2026
Quick Overview
Given candidate ads with (id, duration_seconds, value, advertiser_category) and an ad break of pod_seconds, choose ads with total duration at most pod_seconds that maximize total value while using at most one ad per category.
Roku
November 29, 20260
0
0 solved
Given candidate ads with (id, duration_seconds, value, advertiser_category) and an ad break of pod_seconds, choose ads with total duration at most pod_seconds that maximize total value while using at most one ad per category.
Roku's ad platform assembles mid-roll pods for The Roku Channel and partner apps, and advertisers do not want to run next to a competitor in the same break. This tests whether you can map a business rule onto a grouped knapsack and reconstruct the chosen set, not just the optimal value.
What the Interviewer Expects
- Identifies the problem as 0/1 knapsack with groups (at most one item per group)
- Processes groups so that within a group each item extends only the previous group's table
- Reconstructs the chosen ads, not only the value
- States pseudo-polynomial complexity in pod length and explains why it is fine for breaks under a few minutes
- Discusses what happens when no ad fits
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
- How would you require the pod to be filled to within 5 seconds of its length?
- How would you add a rule that the same advertiser cannot appear in back-to-back pods for a viewer?
- If durations were arbitrary floats, what would you do?
- How would you handle a latency budget of a few milliseconds per pod decision?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: ads (id, duration, value, category) with integer durations (15, 30, 60 seconds in practice) and a pod length T. Output: best total value and the ad ids. Constraint: total duration <= T and...
High-Level Design
Plain 0/1 knapsack over seconds, with one change: group ads by category and, for each group, compute the new table from the table before that group. Because every item in the group reads from the old ...