Skip to content
BytePatterns

Fewest Clips to Cover a Broadcast

MediumGreedy#greedy#reach-frontier#interval-cover~25m

Problem

A live broadcast ran from second 0 to second T. Several cameras recorded clips given as [start, end], and clips may overlap or run past T. Any clip can be trimmed. Return the fewest clips needed to cover the whole broadcast from 0 to T, or -1 if some moment is missing from every clip.

Examples

Input:  clips = [[0, 2], [4, 6], [8, 10], [1, 9], [1, 5], [5, 9]], T = 10
Output: 3
Why:    [0, 2], then [1, 9], then [8, 10]
Input:  clips = [[0, 1], [1, 2]], T = 5
Output: -1
Why:    nothing was recorded after second 2
Input:  clips = [[0, 4]], T = 3
Output: 1
Why:    edge case, one clip longer than the broadcast is simply trimmed

Hints

0 / 3

Stuck on the idea rather than the code? Jump Game covers it.