Meeting Rooms
Problem statement
You are given meeting time intervals [start, end). Return whether a person can attend all of them — that is, whether any two intervals overlap in time.
Example:
Input:
intervals = [[0, 30], [5, 10], [15, 20]]
Expected output:
false
Why: [0, 30] overlaps both of the later meetings.
Practice on LeetCode: Meeting Rooms
Golang Solution
Sort by start time, then scan adjacent pairs. If the next meeting starts before the previous one ends, there is a conflict.
Time: O(n log n) — sorting
Space: O(1) extra beyond the sort (depending on the runtime)
func canAttendMeetings(intervals [][]int) bool {
sort.Slice(intervals, func(i, j int) bool {
return intervals[i][0] < intervals[j][0]
})
for i := 1; i < len(intervals); i++ {
if intervals[i][0] < intervals[i-1][1] {
return false
}
}
return true
}
