Fill an Ad Pod for Maximum Revenue With Competitive Separation
Last updated: November 29, 2026
Quick Overview
Given an ad pod of C seconds and candidate ads as (advertiser, duration, expected revenue), choose ads that fit in the pod, with at most one ad per advertiser, to maximize total revenue.
Tubi
November 29, 20260
0
0 solved
Given an ad pod of C seconds and candidate ads as (advertiser, duration, expected revenue), choose ads that fit in the pod, with at most one ad per advertiser, to maximize total revenue.
An ad break on Tubi is a pod of several spots, and the ad server has to fill it well while keeping two ads from the same advertiser out of one break. The interviewer is looking for the step from plain 0/1 knapsack to grouped knapsack, plus a reconstruction of the chosen set.
What the Interviewer Expects
- Recognizes a grouped (multiple-choice) knapsack
- Iterates groups so each advertiser contributes at most one ad
- Reconstructs the chosen ads, not just the revenue
- Handles ads longer than the pod and empty input
- States O(n * C) time and notes C is small because spots come in 15-second units
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 prefer filling the pod completely when revenues tie, to avoid dead air?
- Durations are multiples of 15 seconds. How does that change the table size?
- How would you add a rule that two ads from the same industry cannot run back to back?
- Would you run this per request or precompute? What is the latency budget?
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: capacity C seconds and a list of (advertiser, duration, revenue). Output: best revenue and the ads chosen. Constraint: total duration at most C, at most one ad per advertiser. Unfilled sec...
High-Level Design
Group ads by advertiser. dp[t] is the best revenue using exactly t seconds. For each group, build a new table from the previous one where each t either skips the group or takes exactly one member. R...