BackeasyHashing

Unified Segment Set Solution

Problem Statement

Given a collection of intervals, merge any overlapping intervals and return the resulting set of non-overlapping intervals.

Example 1
Input
[[1, 3], [2, 6], [8, 10], [15, 18]]
Output
[[1, 6], [8, 10], [15, 18]]

Explanation: The intervals [1, 3] and [2, 6] overlap, so they are merged into [1, 6]. The remaining intervals do not overlap.

Example 2
Input
[[1, 4], [4, 5]]
Output
[[1, 5]]

Explanation: Although the intervals [1, 4] and [4, 5] only share a boundary, they are still considered overlapping and are merged into [1, 5].

Constraints

  • 1 <= intervals.length <= 1000
  • intervals[i].length == 2
  • 0 <= intervals[i][0] <= intervals[i][1] <= 1000
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free