Intervals · LC #252
Meeting Rooms
Sort meetings by start time and check if any consecutive pair overlaps - if so, the person cannot attend all meetings.
Statement
Problem & Approach
Problem statement, sample I/O, and key reasoning.
Given an array of meeting intervals `[start, end]`, determine if a person can attend all meetings (no overlaps).
Sample I/O
Input: [[0,30],[5,10],[15,20]] Output: false ([0,30] overlaps with [5,10]) Input: [[7,10],[2,4]] Output: true
Intuition
How to Think About It
Intuition
If we sort by start time, the only possible overlaps are between consecutive meetings. A single linear scan after sorting is sufficient - any next.start < prev.end means a conflict.
Core Concept
Sort by start time O(n log n). Then O(n) scan: if intervals[i][0] < intervals[i-1][1] return false. Return true if no conflict found.
When to use
Checking feasibility of a single-person schedule; prerequisite check before more complex scheduling problems.
When NOT to use
When you need the minimum rooms (use Meeting Rooms II); when meetings can be rescheduled.
Key Insights
What to Know Cold
- After sort, overlap detection only needs adjacent pairs - non-adjacent intervals cannot overlap if adjacents don't.
- Overlap condition: next.start < prev.end (strict - [7,10],[10,11] do NOT overlap).
- This is the simplest interval problem; used as a warm-up or phone-screen question.
- Edge case: empty array or single interval - always true.
- Direct application of sorting + linear scan pattern.
1 example
Worked Examples
Can attend all interviews?
Interview slots [[0,30],[5,10],[15,20]] - check feasibility.
Sort by start, scan consecutive pairs.
Output: false
Foundational building block for all interval scheduling; interviewers often use this to gauge comfort with sorting and interval logic.