Meeting Rooms
Problem
Given meeting time intervals, return true if one person can attend all of them — that is, no two meetings overlap.
Example 1
Input: [[0,30], [5,10], [15,20]] Output: false
Example 2
Input: [[7,10], [2,4]] Output: true
Test cases
Case 1
Input: [[0,30],[5,10],[15,20]] Expected: false
Case 2
Input: [[7,10],[2,4]] Expected: true
Case 3
Input: [] Expected: true
View solutionHide solution1 approach
1. Sort by start, check neighbours
Time O(n log n)Space O(1) extra
After sorting, a person can attend all meetings only if each starts no earlier than the previous one ends.
function canAttendMeetings(intervals) { intervals.sort((a, b) => a[0] - b[0]); for (let i = 1; i < intervals.length; i++) if (intervals[i][0] < intervals[i - 1][1]) return false; return true;}