Meeting Rooms — LeetCode 252 Python Solution
EasyLeetCode PremiumArraySorting
- Problem
- #252
- Pattern
- Sorting
- 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
Python
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
| Measure | Complexity |
|---|---|
| Time | O(n \times \log n) |
| Space | O(\log n), where n is the number of meetings auxiliary |
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
On study lists
This problem is on Blind 75 and NeetCode 150.
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 \times \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.