Given meeting time intervals, return the minimum number of conference rooms needed so that no two overlapping meetings share a room.
Turn each meeting into a +1 at its start and a −1 at its end. Sort the events (ends before starts at the same time) and track the running total.
1function minMeetingRooms(intervals: number[][]): number {2const events = intervals.flatMap(([s, e]) => [[s, 1], [e, -1]]);3events.sort((a, b) => a[0] - b[0] || a[1] - b[1]);4let cur = 0, best = 0;5for (const [, delta] of events) {6cur += delta;7best = Math.max(best, cur);8}9return best;10}
Build and sort the events.
Space: play/pause · ←/→: step