Dsa
Intervals
Easy
Longest Clean Video Clip
A video file has a total duration of D seconds (from 0 to D). There are N intervals [start, end) where the video data is corrupted. Find the length of the longest 'clean' (non-corrupted) continuous segment in the video.
Input Format:
The first line contains two integers: D and N.
The next N lines each contain the start and end of a corrupted interval.
Output Format:
Print the length of the longest clean segment.
Example:
Input:
100 2
10 20
50 80
Output:
30
Explanation: Clean segments are [0,10) (len 10), [20,50) (len 30), and [80,100) (len 20). The longest is 30.
Key concepts
intervalsmergesorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now