Dsa
Intervals
Easy
The Silent Highway
A highway is L kilometers long (from 0 to L). There are N radio stations, each covering a specific range [start, end]. Your task is to find the length of the longest stretch of highway that is not covered by any radio station. A gap can occur at the beginning (before the first station), between stations, or at the end (after the last station).
Input Format:
- The first line contains N (number of stations).
- The second line contains L (highway length).
- The next N lines each contain two integers, 'start' and 'end'.
Output Format:
- A single integer representing the length of the longest uncovered gap.
Example:
Input:
2
10
0 2
5 8
Output:
3
(Explanation: Gaps are [2, 5] length 3 and [8, 10] length 2. Max is 3.)
Key concepts
interval merginggap analysis
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