Find the Peak Number of Overlapping Half-Open Intervals

Quick Overview

Given a list of half-open time intervals, return the largest number of intervals active at the same moment. The problem tests sweep-line reasoning over sorted start and end times and the tie rule for an interval that ends exactly when another one begins.

Find the Peak Number of Overlapping Half-Open Intervals

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given a list `intervals` where `intervals[i] = [start_i, end_i]` is a time interval during which an event is active, return the maximum number of intervals that overlap at any single point in time (the concurrency peak). Intervals are half-open: an interval `[start, end)` is active at time `t` if `start <= t < end`. In other words, an interval ending at time `t` does not overlap with one starting at time `t`. ### Function Signature ```python def max_concurrency(intervals: list[list[int]]) -> int: ``` ### Rules - Each interval is a two-element list `[start, end]` and covers the times `start <= t < end`. - The intervals can arrive in any order. - Repeated intervals count separately: two copies of `[1, 5]` give a concurrency of 2 at every point of `[1, 5)`. ### Constraints - `1 <= len(intervals) <= 10^5` - `len(intervals[i]) == 2` - `0 <= start_i < end_i <= 10^9` ### Examples ```text Input: intervals = [[1, 4], [2, 5], [3, 6], [7, 8]] Output: 3 ``` At time 3 the intervals `[1, 4)`, `[2, 5)` and `[3, 6)` are all active. `[7, 8)` starts after the other three have ended, so no point has four active intervals. ```text Input: intervals = [[1, 3], [3, 5], [5, 7]] Output: 1 ``` Because the intervals are half-open, `[1, 3)` and `[3, 5)` do not overlap at time 3, and the same holds for `[3, 5)` and `[5, 7)` at time 5. The peak concurrency is 1. ```text Input: intervals = [[1, 5], [1, 5], [5, 6]] Output: 2 ``` Both copies of `[1, 5)` are active on `[1, 5)`. At time 5 they have ended and only `[5, 6)` is active.

Overview: Given a list of half-open time intervals, return the largest number of intervals active at the same moment. The problem tests sweep-line reasoning over sorted start and end times and the tie rule for an interval that ends exactly when another one begins.

Nov 24, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given a list intervals where intervals[i] = [start_i, end_i] is a time interval during which an event is active, return the maximum number of intervals that overlap at any single point in time (the concurrency peak).

Intervals are half-open: an interval [start, end) is active at time t if start <= t < end. In other words, an interval ending at time t does not overlap with one starting at time t.

Function Signature

def max_concurrency(intervals: list[list[int]]) -> int:

Rules

  • Each interval is a two-element list [start, end] and covers the times start <= t < end .
  • The intervals can arrive in any order.
  • Repeated intervals count separately: two copies of [1, 5] give a concurrency of 2 at every point of [1, 5) .

Constraints

  • 1 <= len(intervals) <= 10^5
  • len(intervals[i]) == 2
  • 0 <= start_i < end_i <= 10^9

Examples

Input: intervals = [[1, 4], [2, 5], [3, 6], [7, 8]]
Output: 3

At time 3 the intervals [1, 4), [2, 5) and [3, 6) are all active. [7, 8) starts after the other three have ended, so no point has four active intervals.

Input: intervals = [[1, 3], [3, 5], [5, 7]]
Output: 1

Because the intervals are half-open, [1, 3) and [3, 5) do not overlap at time 3, and the same holds for [3, 5) and [5, 7) at time 5. The peak concurrency is 1.

Input: intervals = [[1, 5], [1, 5], [5, 6]]
Output: 2

Both copies of [1, 5) are active on [1, 5). At time 5 they have ended and only [5, 6) is active.