Description

You are given a series of video clips from a sporting event that occurred for time seconds. Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time], or -1 if impossible.

Examples

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

[0,2] + [1,9] + [8,10] covers [0,10].

Input:clips = [[1]], time = 10
Output:1
Explanation:

Minimal case with a single-element matrix.

Input:clips = [[0,4],[2,8],[7,12]], time = 12
Output:3
Explanation:

The requirement is all three clips to cover [0,12]. [0,4] covers the beginning, [2,8] fills the middle with overlap, and [7,12] covers the end. It is not possible to reduce to fewer clips because removing any clip would leave gaps in coverage.

Constraints

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!