A video editor builds a highlight reel from recorded clips. Clip i covers the time from clips[i][0] to clips[i][1] seconds. Clips can be trimmed, and they may overlap.
Write fewestClips(clips, duration) that returns the fewest clips needed to cover the whole timeline from 0 to duration with no gaps, or -1 if it can't be covered. Clips that touch, like [0, 4] and [4, 7], leave no gap.
Input: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], duration = 10 Output: 3
Use [0, 2], [1, 9], and [8, 10].
Input: clips = [[0,1],[1,2]], duration = 5 Output: -1
Nothing covers the time after 2.
0 <= clips.length <= 1000000 <= clips[i][0] <= clips[i][1] <= 10^91 <= duration <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #593 Fewest Clips to Cover the Timeline. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.