MEDIUM NC#134 Blind #39 Intervals

253. Meeting Rooms II

๐Ÿ“– Problem

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

๐Ÿง  Visual Learning Aid

1 Model the input into the right structure
2 Choose the core technique and invariant
3 Execute step-by-step with a sample
4 Validate complexity and edge cases

JS/TS Refreshers

  • โ€ขArray methods (`push`, `pop`, `shift`, `slice`)
  • โ€ขObject/Map/Set usage patterns
  • โ€ขFunction parameter and return typing

Logical Thinking Concepts

  • โ€ขDefine invariants before coding
  • โ€ขCheck edge cases first (`[]`, single element, duplicates)
  • โ€ขEstimate time/space before implementation

๐Ÿ’ก Approach

  • โ†’ Sort start and end times separately
  • โ†’ When meeting starts, need a room
  • โ†’ When meeting ends, free up a room
  • โ†’ Track max rooms needed at any point
  • โ†’ Time: O(n log n), Space: O(n)

๐Ÿ› ๏ธ Hints & Pitfalls

Hints

  • โ€ขSort start and end times separately
  • โ€ขWhen meeting starts, need a room
  • โ€ขWhen meeting ends, free up a room

Common Pitfalls

  • โ€ขTrack max rooms needed at any point
  • โ€ขTime: O(n log n), Space: O(n)

๐Ÿงช Test Cases

Hidden tests on submit: 1

Test Case 1
Not run
Input:
minMeetingRooms([[0,30],[5,10],[15,20]]);
Expected:
2
Test Case 2
Not run
Input:
minMeetingRooms([[7,10],[2,4]]);
Expected:
1
Test Case 3
Not run
Input:
minMeetingRooms([[1,2],[2,3],[3,4]]);
Expected:
1

๐Ÿ“ Code Editor

๐Ÿ“š Reference Solution

โ–ผ
โŒ˜K Search โŒ˜โ†ฉ Run โŒ˜S Submit