Skip to content

Practice Video Stitching

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1024
LeetCode Problem

Video Stitching

Problem Statement

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] = [starti, endi] indicates that the ith clip started at starti and ended at endi. We can cut these clips into segments freely. 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.

Source: Video Stitching on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10
Output
3

# Example 2

Input
clips = [[0,1],[1,2]], time = 5
Output
-1

# Example 3

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,5],[5,7],[6,9]], time = 9
Output
3

Constraints

1 <= clips.length <= 100
0 <= starti <= endi <= 100
1 <= time <= 100

Related LeetCode Problems

Practice more problems similar to Video Stitching.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.