PIXELBANKv9.1.0
Menu

Given an array of intervals [start, end], merge all overlapping intervals and return the result.

Input: intervals as start:end comma-separated. Output: merged intervals, one per line.

Example:

Input:
1:3,2:6,8:10,15:18
Output:
1 6
8 10
15 18
Reasoning:
  • The input intervals are first split into individual intervals: [1:3], [2:6], [8:10], [15:18]
  • Overlapping intervals are merged: [1:3] and [2:6] overlap, resulting in [1:6], while [8:10] and [15:18] do not overlap with any other intervals
  • The merged intervals are then checked for any further overlaps, but since [1:6], [8:10], and [15:18] do not overlap, they remain as separate intervals
  • The final merged intervals are output in the required format: 1 6 8 10 15 18

Constraints:

  • 1 <= len(intervals) <= 10^4
  • 0 <= start <= end <= 10^4
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.