ORIGINAL CODING QUESTION
Concurrent mentoring rooms
Mentoring sessions use half-open intervals [start, end). Find the minimum number of rooms needed. A room ending at time t can be reused by a session starting at t.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, followed by n start/end integer pairs. Print the minimum room count.
Constraints
1 ≤ n ≤ 10,000; 0 ≤ start < end ≤ 1,000,000.
Example 1
Input
3 0 10 5 15 10 20
Output
2
At most two sessions overlap.
Example 2
Input
2 0 5 5 9
Output
1
The same room can serve both sessions.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
The answer is the maximum number of overlapping intervals.
Hint 2
Turn each start into +1 and each end into -1, then sort events.
Hint 3
At equal times process ends before starts because intervals are half-open.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →