Dsa
Intervals
Easy
Video Buffer Continuity
A video player downloads chunks of a video. Each chunk covers a time range [start, end]. The player starts at time 0. It can play continuously as long as the current time is covered by at least one downloaded chunk. Find the furthest timestamp T the player can reach starting from 0 without hitting a gap.
Input Format:
- Line 1: N (number of chunks).
- Line 2: V (total video duration).
- Next N lines: start and end of each chunk.
Output Format:
- The furthest reached timestamp (integer, capped at V).
Example:
Input:
3
100
0 20
15 40
50 80
Output:
40
(Explanation: Chunks [0,20] and [15,40] merge to [0,40]. Since no chunk covers time 40, the player stops.)
Key concepts
interval merginggreedy
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