Reported October 2026
Googlesorting

Merge Intervals

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

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

Intervals like [8,10] and [10,18] touching at a single point still count as overlapping in this Google OA, reported in October 2026. That one detail decides whether your answer passes or quietly fails on edge cases. It's the classic merge intervals problem, an array and sorting task dressed up with closed endpoints. If you've seen it, you can write it in ten minutes. If you haven't, the trick is short. And if your mind goes blank mid-assessment, StealthCoder runs invisibly on screen as a safety net, reads the problem, and gives you a solution in real time.

The problem

Given an array of closed integer intervals intervals, where each interval is [start, end], merge every pair of overlapping intervals.

Examples
Example 1
intervals = [[1,3],[2,6],[8,10],[10,18]]
return = [[1,6],[8,18]]
Intervals [1,3] and [2,6] overlap. Intervals [8,10] and [10,18] touch at endpoint 10, so they also merge.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Sort the intervals by start value. Then walk through them once, keeping a result list. If the current interval's start is less than or equal to the last merged interval's end, they overlap, so set the last end to the max of both ends. Otherwise, push the current interval as new. The pitfall is the comparison. Because the intervals are closed, [8,10] and [10,18] merge, so you need <= and not <. The second pitfall is using the current end instead of the max, which breaks on cases like [1,10] followed by [2,3]. Time is O(n log n) for the sort, with O(n) extra space for output. Also copy intervals rather than mutating shared references if you're unsure. If you freeze on any of this during the live OA, StealthCoder is the hedge, since it stays hidden from the proctor and hands you working code.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Merge 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

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 Google's OA.

Google reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Intervals FAQ

What's the trick to the Google merge intervals question?+

Sort by start, then sweep once. Compare each interval's start to the last merged end. If start is less than or equal to that end, extend the end using the max of the two. Otherwise append a new interval. Everything else is bookkeeping.

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

Yes. The example in this problem shows exactly that, and the result is [8,18]. Use <= when checking overlap. Using strict < is the most common bug and will fail the hidden tests that include shared endpoints.

How hard is this problem really?+

It's medium on paper but easy once you know the sort-then-sweep pattern. Most of the difficulty is remembering the max on the end value and handling the closed endpoint. Expect to finish quickly if you've seen it before.

What's the time and space complexity?+

Sorting dominates at O(n log n). The sweep itself is O(n). Output space is O(n) in the worst case where nothing overlaps. If an interviewer asks, say you could skip extra space only by mutating the input, which is usually not worth it.

How do I prepare in 48 hours?+

Write this one from scratch twice without looking. Then test it on an empty array, a single interval, fully nested intervals like [1,10] and [2,3], and touching endpoints. That covers nearly every failure mode this Google problem can throw at you.

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

OA at Google?
Invisible during screen share
Get it