Meeting Rooms II

Medium
Intervals

Given an array of meeting time intervals where intervals[i] = [start_i, end_i], return the minimum number of conference rooms required.

Key insight: We need to find the maximum number of overlapping meetings at any point in time. This can be solved using:

  1. Min-heap approach: Sort by start time. Use a min-heap to track meeting end times. For each meeting, remove all ended meetings, then add the current one.

  2. Event-based approach: Create separate arrays for start and end times. Sort both. Use two pointers to count active meetings.

  3. Sweep line: Mark +1 at each start, -1 at each end. The maximum running sum is the answer.

Real-world analogy: You're a facility manager figuring out how many conference rooms to book for a day's meetings.

Example 1

Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2
Explanation: At time 5, both [0,30] and [5,10] are active. At time 15, [0,30] and [15,20] are active. Maximum 2 rooms needed.

Example 2

Input: intervals = [[7,10],[2,4]]
Output: 1
Explanation: These meetings do not overlap. One room is sufficient.

Example 3

Input: intervals = [[1,5],[2,6],[3,7],[4,8]]
Output: 4
Explanation: At time 4, all four meetings are active simultaneously.

Constraints

  • 1 <= intervals.length <= 10^4
  • 0 <= start_i < end_i <= 10^6
Show Hints (4)
Hint 1: Think about what happens at each point in time. How many meetings are active?
Hint 2: Could you use a min-heap to track which meetings have ended?
Hint 3: Alternative: separate the start and end times into two arrays.
Hint 4: The answer is the maximum number of concurrent meetings.
Loading editor...

Test Results

Click "Run" to execute your code against test cases

AI Tutor

Socratic guidance - I'll ask questions, not give answers

AI Tutor
Hello! I'm your AI tutor, here to guide you through this problem using the Socratic method. I won't give you direct answers, but I'll ask questions and provide hints to help you discover the solution yourself. What's your first instinct when you look at this problem? What approach comes to mind?