Reported September 2026
Applied Intuitionarray

Merge Overlapping Closed Intervals

Reported by candidates from Applied Intuition's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Applied Intuition OA. Under 2s to a working solution.
Founder's read

The whole problem hinges on one thing: a sorted array of intervals and a result list you keep appending to. Applied Intuition candidates reported this one in September 2026, and it's a clean merge-intervals question with a twist on touching endpoints. Intervals like [8,10] and [10,12] must fuse into [8,12]. If your invite lands in the next day or two, expect this shape. Sort by start, sweep once, extend or push. It's short, but the edge cases will bite if you rush. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment.

The problem

Given closed integer intervals [start, end], merge every pair that overlaps or touches at an endpoint. Return disjoint intervals sorted by start.

Function
mergeIntervals(intervals: int[][]) → int[][]

Examples
Example 1
intervals = [[1,3],[2,6],[8,10],[10,12]]
return = [[1,6],[8,12]]
The first two overlap and the last two touch at 10.
Example 2
intervals = [[5,7]]
return = [[5,7]]
One interval is already merged.
Example 3
intervals = [[4,5],[1,10],[2,3]]
return = [[1,10]]
The containing interval absorbs both others.

Constraints
1 <= intervals.length <= 10^5.
-10^9 <= start <= end <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is sorting by start, then one pass. Keep the last interval in your result list. For each new interval, if its start is less than or equal to the last end, set last end to the max of both ends. Otherwise append it as a new interval. The pitfall is the comparison. Touching counts as overlap here, so use <= and not <. Example 1 proves it with [8,10] and [10,12]. The second pitfall is forgetting the max. Example 3 has [1,10] swallowing [2,3], so assigning the new end directly would shrink the result to [1,3]. Also copy intervals or sort in place deliberately. With up to 10^5 intervals, O(n log n) from the sort is fine, and values reach 10^9 in magnitude, so don't invent sentinel values. If you freeze during the live OA, StealthCoder can surface this sweep so you can type it out calmly.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Merge Overlapping Closed Intervals cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as merge intervals. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Applied Intuition's OA.

Applied Intuition reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Overlapping Closed Intervals FAQ

How hard is the Applied Intuition merge intervals question really?+

It's a standard medium. The logic is about ten lines once you see it. The difficulty is in details: touching endpoints count as overlap, and contained intervals must not shrink the end. Candidates who miss those two get wrong answers on hidden tests.

What's the trick to merging overlapping closed intervals?+

Sort by start, then sweep once. Compare each interval's start to the last merged end. If start <= last end, extend the end with max(lastEnd, end). Otherwise push a new interval. That single pass after sorting is the whole solution.

Do touching intervals like [8,10] and [10,12] merge?+

Yes. The problem says closed intervals that overlap or touch at an endpoint get merged. Use start <= lastEnd, not strictly less than. Example 1 shows [8,10] and [10,12] becoming [8,12], so a strict comparison fails that case.

What complexity should I target with 10^5 intervals?+

O(n log n) time from sorting, plus O(n) for the sweep, and O(n) output space. Anything quadratic risks timing out at 10^5 intervals. Sorting is the dominant cost, so don't try to be cleverer than that.

How do I prepare for this in 48 hours?+

Write the sort-and-sweep from memory twice. Then test three cases: a single interval, touching endpoints, and one interval containing others. Also check negative values and unsorted input. That covers the edge cases this problem is built around.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Applied Intuition.

OA at Applied Intuition?
Invisible during screen share
Get it