Merge Intervals (Scheduling)

Problem Merge overlapping time intervals (e.g., busy slots) and find the free gaps between them.

Input / Output

  • Input: a list of n intervals [start, end].
  • Output: the merged busy intervals (and, if asked, the free gaps between them).

Constraints

  • 1 <= n <= 10^4
  • Intervals may be given in any order and may nest or merely touch.

Example

  • [[1,3],[2,6],[8,10]] → busy [[1,6],[8,10]]; the gap (6,8) is free.
added …
LeaderboardSalaryAccount