Dsa
Intervals
Hard
Interval Gap Finder
Given a set of intervals representing busy time slots in a day, find all the free time intervals, assuming the day starts at 0 and ends at 24. Each interval is given as [start, end]. If there are no free intervals, the output should indicate that.
Input:
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of busy intervals.
The next n lines each contain two integers (0 ≤ start < end ≤ 24) representing busy time slots.
Output:
Print the free time intervals in the format [start, end], or print 'No free time' if the entire day is booked.
Example:
Input:
3
1 2
2 3
4 5
Output:
[0, 1]
[3, 4]
[5, 24]
Key concepts
intervalsgapssorting
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