You're managing a busy conference center and need to determine the minimum number of conference rooms required to accommodate all scheduled meetings without any conflicts.

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], your task is to find the minimum number of conference rooms needed so that no two meetings overlap in the same room.

Key Points:

  • Meetings with the same start and end time as another meeting's end and start time do not overlap
  • A meeting that ends at time t and another that starts at time t can use the same room
  • You need to return the minimum number of rooms required

Example: If you have meetings [[0,30],[5,10],[15,20]], you need 2 rooms because the first meeting (0-30) overlaps with both other meetings.

Input & Output

example_1.py โ€” Basic Overlap
$ Input: intervals = [[0,30],[5,10],[15,20]]
โ€บ Output: 2
๐Ÿ’ก Note: Meeting [0,30] overlaps with both [5,10] and [15,20], but [5,10] and [15,20] don't overlap with each other. So we need 2 rooms: one for [0,30] and another that can be shared by [5,10] and [15,20].
example_2.py โ€” Adjacent Meetings
$ Input: intervals = [[7,10],[2,4]]
โ€บ Output: 1
๐Ÿ’ก Note: These meetings don't overlap - one ends at 4 and the other starts at 7, so they can share the same room sequentially.
example_3.py โ€” All Overlapping
$ Input: intervals = [[9,10],[4,9],[4,17]]
โ€บ Output: 2
๐Ÿ’ก Note: [4,9] and [9,10] don't overlap (first ends when second starts), but [4,17] overlaps with both. Maximum concurrent meetings is 2, so we need 2 rooms.

Visualization

Tap to expand
Meeting Rooms Scheduling ProblemRoom 1Meeting: 0-30Status: OccupiedRoom 2Meeting: 5-10Next: 15-20Room 3AvailableNot neededTimelineMeeting 1: [0, 30][5, 10][15, 20]Minimum Rooms Required: 2Peak concurrency occurs when meetings [0,30] and [5,10] overlapPeak overlap
Understanding the Visualization
1
Receive booking requests
You get meeting requests with start and end times, similar to hotel check-in/check-out
2
Sort by arrival time
Process meetings chronologically by start time, like handling hotel guests as they arrive
3
Track room availability
Use a system (heap) to efficiently track when each occupied room becomes free
4
Optimize room usage
Always reuse the earliest available room to minimize total rooms needed
Key Takeaway
๐ŸŽฏ Key Insight: The minimum number of conference rooms needed equals the maximum number of concurrent meetings at any point in time. Using a min-heap to efficiently track room availability gives us the optimal O(n log n) solution.

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(nยฒ)

For each of n meetings, we might check against all previously placed meetings in worst case

n
2n
โš  Quadratic Growth
Space Complexity
O(n)

We store all meetings distributed across different rooms

n
2n
โšก Linearithmic Space

Constraints

  • 1 โ‰ค intervals.length โ‰ค 104
  • 0 โ‰ค starti < endi โ‰ค 106
  • All meeting times are non-negative integers
Asked in
Google 45 Amazon 38 Microsoft 32 Meta 28 Apple 22
52.0K Views
High Frequency
~25 min Avg. Time
1.9K Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen