Leetcode 1081 Solution
This article provides solution to leetcode question 1081 (video-stitching)
Access this page by simply typing in "lcs 1081" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/video-stitching
Solution
class Solution:
def videoStitching(self, clips: List[List[int]], T: int) -> int:
clips.sort()
end = 0
l = 0
ans = 0
while end < T and l < len(clips):
r = l
next_end = -1
while r < len(clips) and clips[r][0] <= end:
next_end = max(clips[r][1], next_end)
r += 1
if next_end == -1:
return -1
end = next_end
l = r
ans += 1
return ans if end >= T else -1