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
๐ค Output