Point with Maximum Overlapping Intervals

Problem Given a list of intervals [start, end], find the coordinate at which the greatest number of intervals overlap. If several points tie for the maximum, return the earliest one.

Input / Output

  • Input: intervals, an array of [start, end] pairs.
  • Output: the earliest maximally-overlapped point; some variants also ask for the overlap count at that point.

Constraints

  • Number of intervals < 10^5, so checking every pair for overlap at O(n^2) will not pass.
  • Intervals may be nested, identical, or merely touching at an endpoint.
  • Endpoint coordinates may be large or sparse, so allocating one bucket per coordinate is not always viable.
  • Clarify endpoint semantics up front: with closed intervals, [1,3] and [3,5] do overlap at 3.

Example

  • [[1,4],[2,5],[9,12],[5,9],[5,12]] → at point 5 three intervals are live ([2,5], [5,9], [5,12]) under closed-interval semantics, which is the maximum → answer 5.
  • Nested case: [[1,10],[2,3],[2,3]] → 2, where all three overlap; the enclosing interval must not be missed.
asked …
LeaderboardSalaryAccount