Check Whether One Person Can Attend Every Meeting
Company: ByteDance
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
A person has a list of meetings, each with a start time and an end time. Return whether they can attend every meeting, which is possible exactly when no two meetings overlap.
### Function Signature
```python
def can_attend_all(meetings: list[list[int]]) -> bool:
```
### Rules
- `meetings[i] = [start, end]` occupies the half-open interval `[start, end)`: the meeting is in progress at every time `t` with `start <= t < end`.
- Two meetings overlap when some time `t` lies in both intervals. A meeting that ends at `t` and a meeting that starts at `t` do not overlap.
- Identical meetings listed twice are separate meetings, and they overlap each other.
- Return `True` when there are zero meetings or one meeting.
### Constraints
- `0 <= len(meetings) <= 10^5`
- `0 <= start < end <= 10^9` for every meeting
- Times are integers, so every value fits in a 32-bit signed integer.
- `meetings` is in no particular order.
### Examples
**Example 1**
```text
Input: meetings = [[9, 12], [1, 4], [4, 9]]
Output: True
```
In time order the meetings are `[1, 4)`, `[4, 9)` and `[9, 12)`. Each one starts exactly when the previous one ends, so none overlap.
**Example 2**
```text
Input: meetings = [[2, 7], [8, 10], [6, 9]]
Output: False
```
At time `6`, both `[2, 7)` and `[6, 9)` are in progress.
**Example 3**
```text
Input: meetings = [[3, 5], [3, 5]]
Output: False
```
The two copies of `[3, 5)` are both in progress at time `3`.
Overview: A coding question that asks whether one person can attend every meeting in a list of half-open time intervals. It tests interval reasoning, correct treatment of back-to-back and duplicate meetings, and an efficient overlap check that scales to a hundred thousand meetings.
A person has a list of meetings, each with a start time and an end time. Return whether they can attend every meeting, which is possible exactly when no two meetings overlap.
Implement `can_attend_all(meetings)`, where `meetings[i] = [start, end]`.
**Rules**
- Meeting `[start, end]` occupies the half-open interval `[start, end)`: it is in progress at every time `t` with `start <= t < end`.
- Two meetings overlap when some time `t` lies in both intervals. A meeting that ends at time `t` and a meeting that starts at time `t` do not overlap.
- Identical meetings listed twice are separate meetings, and they overlap each other.
- Return `True` (`true` in JavaScript, Java and C++) when no two meetings overlap, otherwise `False` (`false`). With zero meetings or one meeting, return `True`.
**Constraints**
- `0 <= len(meetings) <= 10^5`
- `0 <= start < end <= 10^9` for every meeting
- Times are integers, so every value fits in a 32-bit signed integer (no value exceeds 2^31 - 1).
- `meetings` is in no particular order.
**Example 1**
```text
Input: meetings = [[9, 12], [1, 4], [4, 9]]
Output: True
```
In time order the meetings are `[1, 4)`, `[4, 9)` and `[9, 12)`. Each one starts exactly when the previous one ends, so none overlap.
**Example 2**
```text
Input: meetings = [[2, 7], [8, 10], [6, 9]]
Output: False
```
At time `6`, both `[2, 7)` and `[6, 9)` are in progress.
Constraints
- 0 <= len(meetings) <= 10^5
- meetings[i] = [start, end] with 0 <= start < end <= 10^9 for every meeting
- Times are integers, so every value fits in a 32-bit signed integer
- meetings is in no particular order; identical meetings may be listed more than once
Examples
Input: ([],)
Expected Output: True
Explanation: Empty list: zero meetings can always be attended.
Input: ([[5, 10]],)
Expected Output: True
Explanation: A single meeting has nothing to overlap with.
Hints
- Two meetings [a, b) and [c, d) share a time exactly when a < d and c < b; a meeting ending at t and one starting at t do not.
- The two meetings that overlap need not be next to each other in the input, and comparing every pair is too slow for 10^5 meetings.
- Do not merge or de-duplicate identical meetings: two copies of the same meeting overlap each other.