Video Stitching - Problem
Video Stitching Challenge: You're working as a video editor for a sports broadcasting company. You have multiple video clips from a sporting event that lasted time seconds, and these clips can overlap and have varying lengths. Each clip is represented as [start_i, end_i] indicating when it begins and ends.

Your task is to find the minimum number of clips needed to create a complete coverage of the entire event from [0, time]. You can cut clips into smaller segments (e.g., clip [0, 7] can become [0, 1] + [1, 3] + [3, 7]).

Goal: Return the minimum clips needed to cover [0, time], or -1 if impossible.

Input & Output

example_1.py โ€” Basic Coverage
$ Input: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10
โ€บ Output: 3
๐Ÿ’ก Note: We can use clips [0,2], [1,9], and [8,10] to cover the entire interval [0,10]. The clip [1,9] covers most of the middle portion efficiently.
example_2.py โ€” Impossible Case
$ Input: clips = [[0,1],[2,3]], time = 5
โ€บ Output: -1
๐Ÿ’ก Note: There's a gap between [1,2] that cannot be covered by any available clips, making it impossible to cover [0,5] completely.
example_3.py โ€” Single Clip Solution
$ Input: clips = [[0,1],[1,2]], time = 2
โ€บ Output: 2
๐Ÿ’ก Note: We need both clips: [0,1] covers the first part and [1,2] covers the second part to achieve complete coverage of [0,2].

Visualization

Tap to expand
River (Width = time)Plank APlank B (Best Choice)Plank CPlank D1234Greedy Choice: Always pick plank extending furthest
Understanding the Visualization
1
Survey Available Planks
Sort all planks by their starting position to understand your options
2
Choose Optimal Plank
At each gap, select the plank that extends furthest while covering the current position
3
Place and Advance
Place the chosen plank and move to the new furthest point
4
Complete Bridge
Repeat until the entire river span [0, time] is covered
Key Takeaway
๐ŸŽฏ Key Insight: The greedy approach works because extending coverage as far as possible at each step minimizes the total number of clips needed.

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(2^n ร— n)

2^n subsets to check, each requiring O(n) time to validate coverage

n
2n
โš  Quadratic Growth
Space Complexity
O(n)

Space for storing current subset and coverage tracking

n
2n
โšก Linearithmic Space

Constraints

  • 1 โ‰ค clips.length โ‰ค 100
  • 0 โ‰ค starti โ‰ค endi โ‰ค 100
  • 1 โ‰ค time โ‰ค 100
  • Each clip can be used at most once
Asked in
Google 25 Amazon 18 Meta 12 Microsoft 8
38.0K Views
Medium Frequency
~15 min Avg. Time
1.2K 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