Count Ways to Fill an Ad Break With Fixed-Length Clips
Last updated: November 29, 2026
Quick Overview
A YouTube ad break lasts exactly T seconds and can be filled with clips whose lengths come from a small set (for example 6, 15 and 30 seconds). Count the ordered sequences of clips that fill the break exactly, modulo 1,000,000,007.
0
0
0 solved
A YouTube ad break lasts exactly T seconds and can be filled with clips whose lengths come from a small set (for example 6, 15 and 30 seconds). Count the ordered sequences of clips that fill the break exactly, modulo 1,000,000,007.
A warm-up in the style of Google phone screens: a counting problem wrapped in an ads scenario that reduces to a classic stair-climbing recurrence. The interviewer checks that you spot that order matters, write the recurrence cleanly, and handle the modulus.
What the Interviewer Expects
- Recognize that order matters, so this counts compositions, not combinations
- State dp[t] as the number of sequences filling exactly t seconds
- Use dp[0] = 1 as the base case and explain why
- Iterate t outward and sum over clip lengths
- Apply the modulus at each addition
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 the answer change if two clips of the same length are indistinguishable regardless of order?
- What if the same advertiser cannot run twice in a row?
- T is up to 10^18 and there are three clip lengths. How do you compute it fast?
- How would you return one valid sequence instead of the count?
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: a list lengths of distinct positive integers and a target T. Output: the number of ordered sequences of clips (repetition allowed) whose total is exactly T, modulo . Two sequences...
High-Level Design
Let dp[t] be the number of ways to fill exactly t seconds. The last clip in any sequence has some length L, and what comes before it fills t - L seconds, so dp[t] = sum(dp[t - L]) over lengt...