> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Meeting Rooms Python Solution with Tests

> Tested Python solution for LeetCode 252 with 18 pytest cases. Generate a practice environment with lcpy.

LeetCode 252, Easy. Topics: Array, Sorting. [View on LeetCode](https://leetcode.com/problems/meeting-rooms/description/).

Generate this problem as a practice environment: tested reference solution, 18 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 252   # by problem number
lcpy gen -s meeting_rooms   # by problem name
```

## Problem

Given an array of meeting time intervals consisting of start and end times `[[s1,e1],[s2,e2],...]` (si \< ei), determine if a person could attend all meetings.

### Examples

```
Input: [[0,30],[5,10],[15,20]]
Output: false
```

```
Input: [[7,10],[2,4]]
Output: true
```

### Constraints

* 0 \<= intervals.length \<= 10^4
* intervals\[i].length == 2
* 0 \<= starti \< endi \<= 10^6

**Note:** Input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/meeting_rooms/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/meeting_rooms/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n log n)
    # Space: O(1)
    def can_attend_meetings(self, intervals: list[list[int]]) -> bool:
        if not intervals:
            return True

        # Sort intervals by start time
        intervals.sort(key=lambda x: x[0])

        # Check for overlaps
        return all(intervals[i][0] >= intervals[i - 1][1] for i in range(1, len(intervals)))
```

## Complexity

| Time       | Space |
| ---------- | ----- |
| O(n log n) | O(1)  |

## Tags

[Grind](/catalog/grind), [Blind 75](/catalog/blind-75), [NeetCode 150](/catalog/neetcode-150), [NeetCode 250](/catalog/neetcode-250), [NeetCode All](/catalog/neetcode).
