Created
September 9, 2022 08:03
-
-
Save AsifITk/489a699a52d91048af700b0c39feddf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let minClipNeeded = (clips, time) => { | |
clips.sort((a, b) => { | |
if (a[0] === b[0]) { | |
return b[1] - a[1]; | |
} | |
else { | |
return a[0] - b[0]; | |
} | |
}); | |
if (clips[0][0] !== 0) { | |
return -1; | |
} | |
let limit = 0; | |
let curr = 0; | |
let endLimit = 0; | |
let i = 0; | |
while (i < clips.length && clips[i][0] <= limit) { | |
while (i < clips.length && clips[i][0] <= limit) { | |
endLimit = Math.max(endLimit, clips[i][1]); | |
i++; | |
} | |
curr++; | |
limit = endLimit; | |
if (limit >= time) { | |
return curr; | |
} | |
} | |
return -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment