Determine whether one person can attend all meetings without overlap

Quick Overview

Decide whether one person can attend every meeting in a list of start and end times, where a meeting that ends as another begins is not a conflict. It tests sorting intervals, the adjacent overlap check and careful handling of touching endpoints.

Determine whether one person can attend all meetings without overlap

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given a list of meetings. Each meeting is a pair `[start, end]` with `start < end`. Decide whether one person can attend every meeting, which is possible only when no two meetings overlap. A meeting that ends exactly when another one begins is not a conflict. For example, `[8, 10]` and `[10, 12]` can both be attended. ### Function Signature ```python def can_attend_meetings(intervals: list[list[int]]) -> bool: ``` ### Rules - Each interval is a list of two integers `[start, end]`. The list is not necessarily sorted. - Two meetings `[a, b]` and `[c, d]` conflict when `max(a, c) < min(b, d)`. Meetings that only share an endpoint do not conflict. - Return `True` when no pair of meetings conflicts, and `False` otherwise. An empty list or a single meeting returns `True`. ### Constraints - `0 <= len(intervals) <= 10^4` - `0 <= start < end <= 10^4` ### Examples ```text Input: intervals = [[1, 40], [15, 25], [35, 45]] Output: False ``` `[1, 40]` overlaps `[15, 25]` because 15 comes before 40, and it also overlaps `[35, 45]`. One conflict is enough to make the answer `False`. ```text Input: intervals = [[2, 7], [8, 12]] Output: True ``` The first meeting ends at 7 and the second starts at 8, so they do not overlap. ```text Input: intervals = [[10, 12], [8, 10]] Output: True ``` The list is out of order. In time order, `[8, 10]` ends at 10, exactly when `[10, 12]` starts, and the rules treat that as no conflict.

Overview: Decide whether one person can attend every meeting in a list of start and end times, where a meeting that ends as another begins is not a conflict. It tests sorting intervals, the adjacent overlap check and careful handling of touching endpoints.

Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of meetings. Each meeting is a pair [start, end] with start < end. Decide whether one person can attend every meeting, which is possible only when no two meetings overlap.

A meeting that ends exactly when another one begins is not a conflict. For example, [8, 10] and [10, 12] can both be attended.

Function Signature

def can_attend_meetings(intervals: list[list[int]]) -> bool:

Rules

  • Each interval is a list of two integers [start, end] . The list is not necessarily sorted.
  • Two meetings [a, b] and [c, d] conflict when max(a, c) < min(b, d) . Meetings that only share an endpoint do not conflict.
  • Return True when no pair of meetings conflicts, and False otherwise. An empty list or a single meeting returns True .

Constraints

  • 0 <= len(intervals) <= 10^4
  • 0 <= start < end <= 10^4

Examples

Input: intervals = [[1, 40], [15, 25], [35, 45]]
Output: False

[1, 40] overlaps [15, 25] because 15 comes before 40, and it also overlaps [35, 45]. One conflict is enough to make the answer False.

Input: intervals = [[2, 7], [8, 12]]
Output: True

The first meeting ends at 7 and the second starts at 8, so they do not overlap.

Input: intervals = [[10, 12], [8, 10]]
Output: True

The list is out of order. In time order, [8, 10] ends at 10, exactly when [10, 12] starts, and the rules treat that as no conflict.