noodleProblems/
Largest Overlap of Intervals
#125

Largest Overlap of Intervals

AlgorithmmediumArraySorting

You are given a list of intervals where each intervals[i] = [start, end] is a closed range. Several intervals may cover the same point at once.

Return the **largest number of intervals that overlap at any single point** — the peak number of simultaneously active intervals. Touching endpoints count as overlapping: [1, 3] and [3, 5] both cover the point 3, so at 3 two intervals are active.

Example cases

  • triple stack
    in intervals =
    15
    26
    37
    out 3
    At point 3, all three intervals are active, so the peak overlap is 3.
  • disjoint
    in intervals =
    12
    34
    56
    out 1
    No two intervals share a point; the peak is 1.
  • empty
    in intervals = []
    out 0

Constraints

  • 0 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start <= end <= 10^9
Saved
intervals =
[[1,5],[2,6],[3,7]]