1024. Video Stitching Medium
1/**
2 * [1024] Video Stitching
3 *
4 * 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.
5 * 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.
6 * We can cut these clips into segments freely.
7 *
8 * For example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].
9 *
10 * 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.
11 *
12 * Example 1:
13 *
14 * Input: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10
15 * Output: 3
16 * Explanation: We take the clips [0,2], [8,10], [1,9]; a total of 3 clips.
17 * Then, we can reconstruct the sporting event as follows:
18 * We cut [1,9] into segments [1,2] + [2,8] + [8,9].
19 * Now we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].
20 *
21 * Example 2:
22 *
23 * Input: clips = [[0,1],[1,2]], time = 5
24 * Output: -1
25 * Explanation: We cannot cover [0,5] with only [0,1] and [1,2].
26 *
27 * Example 3:
28 *
29 * 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
30 * Output: 3
31 * Explanation: We can take clips [0,4], [4,7], and [6,9].
32 *
33 *
34 * Constraints:
35 *
36 * 1 <= clips.length <= 100
37 * 0 <= starti <= endi <= 100
38 * 1 <= time <= 100
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/video-stitching/
44// discuss: https://leetcode.com/problems/video-stitching/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn video_stitching(clips: Vec<Vec<i32>>, time: i32) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_1024() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.