R
|
🔥Problem of the Day+50 XPDev Score: 780/1000
All Problems (8)
MediumIntervals•Acceptance: 47.1%

Merge Intervals: Calendar Optimizer

Real-World Engineering Context
Google Calendar and Outlook meeting scheduler algorithms collapse free/busy slot blocks to identify overlapping availability across teams.
Given an array of `intervals` where `intervals[i] = [start_i, end_i]`, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

Sample Test Cases

Input: [[[1,3],[2,6],[8,10],[15,18]]]
Expected: [[1,6],[8,10],[15,18]]
Input: [[[1,4],[4,5]]]
Expected: [[1,5]]
Input: [[[1,10],[2,6]]]
Expected: [[1,10]]

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start_i <= end_i <= 10^4