Dsa
Intervals
Easy
The Library Silence
A library tracks room occupancy. Given a set of booking intervals [start, end], find the longest continuous duration during which at most K rooms are occupied simultaneously. The library is open from time 0 to MaxTime.
Example:
Input:
N=2, K=1, MaxTime=50
Bookings: [10, 20], [15, 25]
Timeline:
0-10: 0 rooms (OK)
10-15: 1 room (OK)
15-20: 2 rooms (Not OK)
20-25: 1 room (OK)
25-50: 0 rooms (OK)
Valid intervals: [0, 15] and [20, 50]. The longest is 30.
Key concepts
intervalssweep linecoordinate compression
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