Cheapest Order to Split a Video Timeline at Required Cut Points

Last updated: November 29, 2026

Quick Overview

A video of length L must be cut at a given set of positions. Each cut costs the length of the segment being cut at that moment. Return the minimum total cost to make all the cuts, in any order.

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

0

0

0 solved


A video of length L must be cut at a given set of positions. Each cut costs the length of the segment being cut at that moment. Return the minimum total cost to make all the cuts, in any order.

Framed around a Reels or Instagram video editor that splits a clip into segments, this is an interval DP question in Meta's onsite style. The interviewer checks that you reframe from positions to sorted cut indices and recognize the matrix chain shape.

What the Interviewer Expects
  • Sort cuts and add the endpoints 0 and L
  • Define dp[i][j] over cut indices, not raw positions
  • Recognize that the cost of the first cut in a segment is the segment length
  • Fill by increasing interval width
  • Explain why greedy (cut the middle first) fails
Key Topics to Cover
Interval dynamic programming
Matrix chain pattern
Sorting
Optimal ordering
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
  • Why is the state over cut indices rather than positions?
  • How would you return the actual order of cuts?
  • Can Knuth's optimization reduce this below cubic time?
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: integer L >= 2 and a list of distinct integer cuts with 0 < cut < L, up to about 100 of them. Return the minimum total cost. With no cuts the cost is 0....

High-Level Design

Sort the cuts and set pts = [0] + sorted(cuts) + [L]. Let dp[i][j] be the minimum cost to make every cut strictly between pts[i] and pts[j], given that segment is currently whole. Whichever cu...


Submit Your Answer
Markdown supported