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
Your task is to find the minimum number of clips needed to create a complete coverage of the entire event from
Goal: Return the minimum clips needed to cover
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
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
โ Quadratic Growth
Space Complexity
O(n)
Space for storing current subset and coverage tracking
โก Linearithmic Space
Constraints
- 1 โค clips.length โค 100
- 0 โค starti โค endi โค 100
- 1 โค time โค 100
- Each clip can be used at most once
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code