Video Stitching - Problem

You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.

Each video clip is described by an array clips where clips[i] = [start_i, end_i] indicates that the ith clip started at start_i and ended at end_i.

We can cut these clips into segments freely. For example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].

Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.

Input & Output

Example 1 — Basic Coverage
$ Input: clips = [[0,2],[1,9],[1,5],[3,8]], time = 5
Output: 1
💡 Note: Clip [1,9] alone covers the entire interval [0,5], so only 1 clip is needed
Example 2 — Multiple Clips Needed
$ Input: clips = [[0,1],[1,2]], time = 5
Output: -1
💡 Note: The clips only cover [0,2] but we need to cover [0,5], making it impossible
Example 3 — Optimal Combination
$ Input: clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,6],[5,7],[6,9]], time = 9
Output: 3
💡 Note: Use clips [0,4], [2,6], [6,9] to cover [0,9] with minimum 3 clips

Constraints

  • 1 ≤ clips.length ≤ 100
  • 0 ≤ starti ≤ endi ≤ 100
  • 1 ≤ time ≤ 100

Visualization

Tap to expand
Video Stitching: Cover Time Interval with Minimum ClipsAvailable Clips:[0,2][1,9][1,5][3,8]012345Target: [0,5]Solution: Use clip [1,9] aloneClip [1,9] covers entire interval [0,5]Result: 1 clip needed
Understanding the Visualization
1
Input
Video clips with start/end times and target duration
2
Process
Find minimum clips to cover [0, time]
3
Output
Minimum number of clips needed
Key Takeaway
🎯 Key Insight: Use greedy approach - always pick the clip that extends coverage furthest from current position
Asked in
Google 15 Amazon 12 Apple 8 Microsoft 6
32.0K Views
Medium Frequency
~25 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen