Merge Intervals Visualizer

Sort intervals by start value, scan each candidate, and watch overlapping ranges collapse into the final merged output.

Input
4
Output
0
Step
1/6
Active
-

Interval input

Step controls

Step 1 of 6: Sort intervals by start value before scanning from left to right.

Merge intervals diagram

Sort intervals by start value before scanning from left to right.

Current Overlap Output
-2 21
Sorted intervals
[1, 3]
[2, 6]
[8, 10]
[15, 18]
Current interval

No active interval in this step.

Candidate

No candidate interval in this step.

Committed output

No intervals have been committed to the output yet.

Result

sorted = [[1, 3], [2, 6], [8, 10], [15, 18]]
merged = [[1, 6], [8, 10], [15, 18]]

What is a Merge Intervals Visualizer?

A merge intervals visualizer shows how overlapping ranges are sorted, compared, merged, and added to the final output.

This tool accepts LeetCode-style interval input such as [[1, 3], [2, 6], [8, 10], [15, 18]]. It sorts by start value, keeps a current interval, and steps through each overlap check.

For the full cluster of related tools, browse the Data Structure Visualizers hub.

How to use this merge intervals visualizer

  • Paste intervals in array, comma-separated, or line-separated format.
  • Step through the sorted intervals from left to right.
  • Watch whether each candidate overlaps the current interval.
  • Inspect the committed output intervals and the active interval.
  • Run to the end to see the final merged result.

Merge intervals algorithm

The standard algorithm sorts intervals by their start value. Then it scans once. If the next interval starts before or at the current interval end, the intervals overlap and the current end becomes the larger end. Otherwise, the current interval is committed to the output and the next interval becomes current.

The time complexity is O(n log n) because of sorting, and the scan after sorting is O(n).

Compare this page with the Interval Tree Visualizer, Sorting Algorithm Visualizer, Two Pointers Visualizer, and Prefix Sum Visualizer.

Frequently Asked Questions

What input format does this merge intervals visualizer use?
Paste pairs of numbers in a LeetCode-style array, comma-separated list, or one interval per line.
Do touching intervals merge?
Yes. This visualizer treats intervals as closed ranges, so [1, 4] and [4, 6] merge into [1, 6].
Why do intervals need to be sorted first?
Sorting by start value makes every overlap decision local: compare only the next interval with the current merged interval.
What is the time complexity of merging intervals?
The usual complexity is O(n log n) because intervals are sorted before the linear merge pass.

Related tools