UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

Free eBooks·About·Changelog·Privacy Policy·Terms of Service·Report a bug
HomeCompetitive ProgrammingInterval Merger

Related Tools

Code FormatterMatrix GeneratorComplexity CalcBit VisualizerBitmask PlannerPrime FactorsMEX CalcMatrix RotationPBDS GeneratorSegment TreeGraph VisualizerStress TesterModulo CalcConvex HullPath FinderOffline JudgeBig-O AnalyzerCombinatoricsDP Table BuilderExtended GCDSieve VisualizerBinary SearchSorting VisualizerSparse Table RMQUnion-Find DSU

Interval Merger Checker

Input pairs of ranges like [1,4],[3,7]. Visualizes overlaps on a timeline and collapses them into merged segments instantly.

You Might Also Like

All Competitive Programming

Segment Tree

Input an array, choose sum/min/max/gcd. See the segment tree visualization and get a complete C++ class template to copy.

Code Formatter

Format and beautify C++, Java, and Python code with consistent indentation. 100% client-side — no code leaves your browser.

Matrix Generator

Generate grid/matrix inputs for competitive programming. Random, zeros, identity, or sequential fill. Outputs in multiple formats.

Complexity Calc

Estimate Big-O operations and runtime for any N. Interactive reference table for all complexity classes from O(1) to O(N!).

Merging intervals is a sort followed by one comparison, and the comparison is where solutions diverge. Does [1,4] merge with [5,7]? Under the standard definition, no: they touch only if the next start is at or before the previous end. The Interval Merger takes that position by default and offers the other convention as an explicit checkbox rather than choosing silently.

Two timelines are drawn to the same scale, the input intervals in rotating colours above and the merged result beneath. Seeing both on one axis is what makes a partial overlap obvious, since a list of number pairs is exactly the representation the human eye is worst at.

The parser is deliberately relaxed. Brackets, parentheses or nothing at all are accepted, so [1,4],[3,7] and 1,4 3,7both work, and a reversed pair such as [7,3] is quietly corrected to [3,7]. Everything computes in the page.

Worked Example: Four Intervals Down to Two

The default input is [1,4],[3,7],[8,10],[9,12]. Sorting by left endpoint leaves the order unchanged. [3,7] starts at 3 which is at or before 4, so it merges into [1,7]. Next comes [8,10], starting after 7, so a new interval opens. Then [9,12] extends it to [8,12]. The stat cards read 4 input, 2 merged and reduced by 2, and the merged list shows [1, 7] and [8, 12].

Edge Cases in the Merge Condition

  • Ticking the gap-of-1 checkbox changes the answer, not the display. With it on, [1,4] and [5,7] collapse to [1,7]. Leave it off when you are checking your own output against a judge.
  • A fully contained interval disappears without widening anything. The Full cover chip loads [1,10],[2,8],[3,5], which merges to a single [1, 10].
  • Sorting is by left endpoint and then by right, which matters when two intervals share a start. Without that tiebreak the merged right endpoint can be wrong.
  • The merged right endpoint is the maximum of the two, not simply the newer one. That is what stops [1,10],[2,3] from collapsing to [1,3].
  • Negative endpoints parse correctly, and the timeline rescales so the leftmost value sits at the axis origin whatever its sign.
  • Text the parser cannot read at all returns Invalid format. Try: [1,4],[3,7] or 1,4 3,7, and a bar narrower than 2% of the axis is widened so a single-point interval stays visible.

4

Input intervals

2

Merged intervals

2

Reduced by

Input Intervals (timeline)

112
[1,4]
[3,7]
[8,10]
[9,12]

Merged Result

112
[1,7]
[8,12]

Merged Intervals (sorted)

[1, 7][8, 12]