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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
1D dynamic programming
Counting compositions
Stair climbing recurrence
Modular arithmetic
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 109+710^9+7. 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...


Submit Your Answer
Markdown supported