Meeting Rooms II

Med
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Meeting Rooms II

Approach

Separate start and end times into two sorted arrays. Use two pointers to sweep through time: when a meeting starts, increment rooms needed; when one ends, decrement. Track the maximum rooms needed at any point. This is equivalent to a line sweep algorithm.

Complexity Analysis

Time
O(n log n)
Space
O(n)

Pattern

Sort + Two Pointers (Sweep Line)

Why It Works

Sorting starts and ends separately lets us process events in chronological order. A start event before the earliest pending end means we need an additional room. Processing ends independently works because we only care about the count of concurrent meetings, not which specific meetings overlap.

Updated Feb 2026