Question bank › Intervals
Dsa Intervals Medium

Finding Gaps Between Time Intervals

You are given a list of time intervals during which an activity occurred. Your job is to determine the gaps of time that remain free between intervals. The output should be a sorted list of these gaps. Input format: The first line contains an integer n (1 <= n <= 10000), the number of intervals. The next n lines each contain two integers representing the start and end time of each interval (0 <= start < end <= 24). Output format: Each gap should be printed on a new line as two integers representing the start and end time of the gap. If there are no gaps, print 'No gaps'. Example: Input: 5 1 3 2 4 5 7 6 8 9 10 Output: 4 5 8 9

Key concepts

intervalsgapsset

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.