Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Leetcode 253. Meeting Rooms II
Given a list of meeting time intervals, determine the minimum number of conference rooms required so that no meetings overlap. The core challenge is computing the maximum number of concurrent intervals (e.g., via sorting with a min-heap of end times or a sweep-line of start/end events).
Asked at:
Amazon
Microsoft
Meta
DESCRIPTION
Given a list of meeting time intervals, determine the minimum number of conference rooms required so that no meetings overlap. The core challenge is computing the maximum number of concurrent intervals (e.g., via sorting with a min-heap of end times or a sweep-line of start/end events).
Input:
Output:
Explanation: At time 5, meetings [0,30] and [5,10] overlap. At time 15, meetings [0,30] and [15,20] overlap. Maximum concurrent meetings is 2, so we need 2 rooms.
Constraints:
- 1 <= intervals.length <= 10^4
- 0 <= start_i < end_i <= 10^6
- Each interval represents a valid meeting time
Understanding the Problem
Let's understand what we're being asked to do. We have a list of meeting time intervals like [[0,30], [5,10], [15,20]], where each interval [start, end] represents a meeting that starts at time start and ends at time end.
We need to determine the minimum number of conference rooms required so that no two meetings overlap in the same room. For example, with [[0,30], [5,10], [15,20]], at time 5 we have two meetings happening simultaneously (the [0,30] meeting and the [5,10] meeting), so we need at least 2 rooms.
Key constraint: Meetings are represented as intervals with start and end times. If one meeting ends exactly when another starts (e.g., [0,10] and [10,20]), they can use the same room (no overlap).
Edge cases to consider: What if all meetings happen at different times (need only 1 room)? What if all meetings overlap completely (need as many rooms as meetings)? What if the intervals list is empty?
Brute Force Approach
The brute force approach checks every pair of meetings to see if they overlap. For each meeting, count how many other meetings it overlaps with. The maximum overlap count plus one gives the minimum rooms needed. This requires comparing every meeting with every other meeting, leading to quadratic time complexity. While simple to understand, this approach becomes impractical for large numbers of meetings.
Start brute force: count overlaps for each meeting
0 / 46
Test Your Knowledge
Login to take the complexity quiz and track your progress
Complexity Analysis
Time Complexity: O(n²) We compare each meeting with every other meeting, resulting in n*(n-1)/2 comparisons, which is O(n²)
Space Complexity: O(1) We only need a constant amount of space to track the maximum overlap count
Building Intuition
The number of rooms needed at any moment equals the number of meetings happening simultaneously at that moment.
The answer is the maximum number of concurrent meetings across all time points. If we track when meetings start and end, we can count how many are active at each moment.
Instead of checking every pair of meetings for overlap (which would be O(n²)), we can process all start and end times in chronological order.
When we encounter a start time, one more room is needed. When we encounter an end time, one room becomes available. The peak concurrent count tells us the minimum rooms required.
Imagine you're managing a building's conference rooms in real-time. You have a counter showing 'Rooms Currently In Use'.
As each meeting starts, increment the counter. As each meeting ends, decrement it. The highest value the counter reaches throughout the day is the minimum number of rooms you need to build.
This is like a 'sweep line' moving through time, tracking the maximum overlap at any point.
Common Mistakes
Optimal Solution
The optimal approach uses a sweep-line algorithm with event processing. Separate all start and end times into events, then sort them chronologically. Process events in order: increment a counter for each start event, decrement for each end event. Track the maximum counter value reached, which represents the peak number of concurrent meetings. Alternatively, use a min-heap to track meeting end times: sort meetings by start time, and for each meeting, remove all ended meetings from the heap before adding the current meeting's end time. The heap size represents rooms needed.
Start: Find minimum meeting rooms using sweep-line algorithm
0 / 25
Test Your Knowledge
Login to take the complexity quiz and track your progress
Complexity Analysis
Time Complexity: O(n log n) Sorting the events (or meetings) takes O(n log n) time. Processing events or maintaining the heap takes O(n log n) in total. The sorting step dominates.
Space Complexity: O(n) We need O(n) space to store the events or the heap, which in the worst case contains all meeting end times
What We've Learned
- Min-heap for tracking active intervals: When dealing with overlapping intervals, use a min-heap to track end times of ongoing events - this allows O(log n) insertion/removal to efficiently determine when resources become available, making it perfect for scheduling and resource allocation problems.
- Sweep-line algorithm pattern: Transform interval problems into point events (start/end) and process them chronologically - this converts a 2D interval problem into a 1D timeline problem where you track the current count of active intervals at each event.
- Sort by start time first: Always sort intervals by start time as your first step - this ensures you process meetings in chronological order and can make greedy decisions about room allocation without missing earlier conflicts.
- Heap size equals resource count: The maximum heap size during processing directly represents the answer - when a new meeting starts, add its end time to the heap; when the earliest ending meeting finishes (heap top ≤ current start), reuse that room by popping and pushing the new end time.
- Two-pointer event processing: An alternative to heaps is creating separate sorted arrays of start and end times, then using two pointers to track when meetings begin vs. end - increment room count on starts, decrement on ends, tracking the maximum concurrent count.
- Real-world resource scheduling: This pattern applies to any resource allocation problem - CPU scheduling, airport runway management, classroom scheduling, or server request handling - wherever you need to determine minimum resources to handle overlapping demands without conflicts.
Related Concepts and Problems to Practice
easy
This is a simpler version of Meeting Rooms II that checks if a person can attend all meetings (no overlaps). It teaches the fundamental interval sorting and overlap detection pattern that is essential before tackling the more complex room allocation problem.
medium
This problem uses similar sorting and sweep-line techniques to merge overlapping intervals. Understanding how to merge intervals helps build intuition for tracking concurrent intervals, which is the core challenge in Meeting Rooms II.
Test Your Understanding
Why is intervals the right data structure for this problem?
intervals provides the optimal access pattern
It's the only data structure that works
It's the easiest to implement
It uses the least memory
Select an answer to see the explanation
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early October, 2025
Mid-level
Early September, 2025
Amazon
Junior
Mid August, 2025
Apple
Senior
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.