EasyNo. 0252LeetCode Premium
Meeting Rooms — LeetCode 252 Python Solution
- Pattern
- Sorting
- Topics
- Array, Sorting
- On study lists
- Blind 75 and NeetCode 150
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.
Example
- Input
- intervals = [[0,30],[5,10],[15,20]]
- Output
- false
Python solution
class Solution:
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
intervals.sort()
return all(a[1] <= b[0] for a, b in pairwise(intervals))Complexity
- Time
- O(n × log n)
- Space · auxiliary
- O(log n)where n is the number of meetings
Pattern: Sorting
Spend O(n log n) once to buy an ordering that makes the rest of the problem trivial. LeetCode 252. Meeting Rooms is filed here because LeetCode tags it Sorting, which is the vocabulary this hub collects.
The sorting guide has the Python template for the pattern and the 401 LeetCode problems that use it.
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2402 | Meeting Rooms III | Hard |
| 0056 | Merge Intervals | Medium |
| 0164 | Maximum Gap | Medium |
| 0274 | H-Index | Medium |
| 0406 | Queue Reconstruction by Height | Medium |
| 0414 | Third Maximum Number | Easy |
Frequently asked questions
- How hard is LeetCode 252. Meeting Rooms?
LeetCode 252. Meeting Rooms is rated Easy on LeetCode.
- What is the time complexity of LeetCode 252. Meeting Rooms?
The Python solution on this page runs in O(n × log n).
- What is the space complexity of LeetCode 252. Meeting Rooms?
The Python solution on this page uses O(log n), where n is the number of meetings auxiliary space.
- What topics does LeetCode 252. Meeting Rooms cover?
LeetCode 252. Meeting Rooms is tagged Array and Sorting on LeetCode.
- Is LeetCode 252. Meeting Rooms a premium problem?
Yes. LeetCode 252. Meeting Rooms is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.