Dsa
Intervals
Easy
Finding Gaps Between Intervals
In a project management tool, you need to identify gaps between scheduled intervals. Given a list of intervals for a project, find the gaps where no work is scheduled.
The program reads from standard input, with the first line containing an integer n, the number of intervals. The next n lines contain two integers each, signifying the start and end times of each interval. The output should list the start and end of each gap, in ascending order.
Input Format:
- An integer n (1 ≤ n ≤ 10000)
- n lines, each containing two integers (start, end) (0 ≤ start < end ≤ 10^9)
Output Format:
- Each gap as "start end" on a new line, if there are gaps. If there are no gaps, print "No Gaps".
Example:
Input:
4
1 3
5 7
8 10
12 15
Output:
3 5
10 12
Key concepts
intervalsgapsoutput
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