Optimal Shot Segmentation Of A Clip With Penalized Cuts

Last updated: November 29, 2026

Quick Overview

Given a per-frame scalar feature for a video (for example mean luminance), split the frames into contiguous shots of at least min_len frames to minimize total within-shot squared error plus a fixed penalty per shot, returning the cost and the shot start indices.

Luma AI
Coding & Algorithms
Machine Learning Engineer
Luma AI
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a per-frame scalar feature for a video (for example mean luminance), split the frames into contiguous shots of at least min_len frames to minimize total within-shot squared error plus a fixed penalty per shot, returning the cost and the shot start indices.

Training data for video models is cut into single-shot clips so a scene change is not learned as motion, which makes shot boundary detection a real data pipeline step. The interviewer checks a correct optimal-partition DP, prefix sums for O(1) segment cost, reconstruction, and the min-length constraint.

What the Interviewer Expects
  • Define the DP state and recurrence precisely
  • Compute segment SSE in O(1) from prefix sums of x and x squared
  • Enforce the minimum shot length and handle infeasible input
  • Reconstruct boundaries via parent pointers
  • Discuss O(n squared) cost and pruning for long videos
Key Topics to Cover
Dynamic programming
Prefix sums
Change point detection
Optimal partitioning
Video preprocessing
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 you extend this to a multi-dimensional embedding per frame?
  • How does PELT pruning reduce the expected cost to near linear?
  • How would you choose the penalty, and what happens as it goes to zero?
  • How would you handle gradual transitions like fades?
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 x[0..n-1], penalty >= 0, min_len >= 1. Choose cut points so each shot has at least min_len frames. Cost = sum over shots of ∑(xi−xˉ)2\sum (x_i - \bar x)^2 plus penalty times the number of sho...

High-Level Design

best[j] = minimum cost to segment the prefix of length j. best[j] = min_i best[i] + SSE(i, j) + penalty over i <= j - min_len. With prefix sums S and Q, $SSE(i, j) = (Q_j - Q_i) - (S_j - S...


Submit Your Answer
Markdown supported

Related Questions