EASY NC#133 Blind #38 Intervals

252. Meeting Rooms

๐Ÿ“– Problem

Given an array of meeting time intervals intervals where intervals[i] = [start_i, end_i], determine if a person could attend all meetings.

๐Ÿง  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 intervals by start time
  • โ†’ Check if any interval overlaps with previous one
  • โ†’ Overlap occurs when current start < previous end
  • โ†’ Time: O(n log n), Space: O(1)

๐Ÿ› ๏ธ Hints & Pitfalls

Hints

  • โ€ขSort intervals by start time
  • โ€ขCheck if any interval overlaps with previous one
  • โ€ขOverlap occurs when current start < previous end

Common Pitfalls

  • โ€ขTime: O(n log n), Space: O(1)

๐Ÿงช Test Cases

Test Case 1
Not run
Input:
canAttendMeetings([[0,30],[5,10],[15,20]]);
Expected:
false
Test Case 2
Not run
Input:
canAttendMeetings([[7,10],[2,4]]);
Expected:
true
Test Case 3
Not run
Input:
canAttendMeetings(intervals: number[][]);
Expected:
Computed from hidden reference

๐Ÿ“ Code Editor

๐Ÿ“š Reference Solution

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