Place Mid-Roll Breaks at Scene Changes to Minimize Longest Stretch

Last updated: November 29, 2026

Quick Overview

Given a runtime, a list of candidate scene-change timestamps, and at most k ad breaks, choose cue points from the candidates that minimize the longest uninterrupted stretch of content, and return that length and the cues.

Tubi
Coding & Algorithms
Software Engineer
Tubi
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a runtime, a list of candidate scene-change timestamps, and at most k ad breaks, choose cue points from the candidates that minimize the longest uninterrupted stretch of content, and return that length and the cues.

Breaking a film mid-sentence hurts viewing, so ad cue points on a streamer like Tubi are best placed at scene changes, while spacing still matters for both viewer experience and inventory. This hard onsite problem checks binary search on the answer with a greedy feasibility test and a correctness argument.

What the Interviewer Expects
  • Recognizes a minimize-the-maximum problem suited to binary search on the answer
  • Writes a greedy feasibility check (jump to the farthest reachable candidate) and argues why greedy is optimal
  • Restricts the search to pairwise distances, or binary searches over integers, and explains the choice
  • Handles infeasible cases where even k breaks cannot cover a long scene
  • Reconstructs the cue points
  • States complexity and tests against a brute force
Key Topics to Cover
Binary search on answer
Greedy
Interval coverage
Proof of correctness
Ad cue points
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
  • Add a constraint that no two breaks may be closer than M seconds. What changes?
  • How would you weight candidates by scene-change confidence instead of treating them equally?
  • How would you solve it with dynamic programming, and when is that better?
  • If exactly k breaks are required for inventory, how do you place the extra ones?
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

Inputs: runtime, unsorted candidates (possibly with duplicates or out-of-range values), and k. Choose at most k candidates; stretches are measured between 0, chosen cues, and runtime. Minimize t...

High-Level Design

Feasibility of a bound d is monotone: if we can keep every stretch at most d with at most k breaks, we can for any larger d. So binary search on d. For a fixed d, greedy is optimal: from the current p...


Submit Your Answer
Markdown supported

Related Questions