Merge Intervals
Reported by candidates from SeekOut's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on Merge Intervals is skipping the sort, then wondering why half the test cases fail. SeekOut reported this one in June 2026, and it's a classic array problem with one clean trick. You get closed intervals, you merge anything that overlaps or touches, and you return them sorted by start. Example 2 matters: [1,4] and [4,5] become [1,5], so touching counts. If you've seen it before, you'll finish fast. If you blank mid-OA, StealthCoder runs invisibly on your desktop as a safety net, so one lost thought doesn't sink the whole attempt.
The problem
Given a collection of closed intervals [start, end], merge every pair that overlaps or touches and return the resulting non-overlapping intervals sorted by start. Function merge(intervals: int[][]) → int[][] Examples Example 1 intervals = [[1,3],[2,6],[8,10],[15,18]] return = [[1,6],[8,10],[15,18]] Example 2 intervals = [[1,4],[4,5]] return = [[1,5]]
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort by start first. Then walk the list once, keeping a result array. For each interval, compare its start to the end of the last merged interval. If start is less than or equal to that end, overlap or touch, so set the last end to the max of both ends. Otherwise push a new interval. The pitfalls are predictable. People use strict less-than and miss the touching case from Example 2. They also assign the end instead of taking the max, which breaks when one interval fully contains another, like [1,10] then [2,3]. Another one is mutating the input without a copy when the platform expects the original untouched. Complexity is O(n log n) for the sort and O(n) for the sweep. If the live OA freezes your brain, StealthCoder is the hedge that gives you this sweep on screen without the proctor seeing it.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as merge intervals. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass SeekOut's OA.
SeekOut reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Merge Intervals FAQ
What's the trick in Merge Intervals?+
Sort by start, then sweep once. Compare each interval's start to the last merged end. If it's less than or equal, extend the end with max. Otherwise start a new interval. Everything else is bookkeeping around that single comparison.
How hard is this really for the SeekOut OA?+
It's a standard medium on paper, but easy once you know the sort-then-sweep idea. SeekOut candidates reported it in June 2026. Most failures come from edge cases, not the algorithm, so spend your time on those.
Do touching intervals like [1,4] and [4,5] merge?+
Yes. Example 2 shows it returns [[1,5]]. Use start <= lastEnd, not start < lastEnd. That one character is the most common reason a correct-looking solution fails hidden tests.
Why take the max of the ends instead of just the new end?+
Because one interval can swallow another. With [1,10] and [2,3], setting the end to 3 would shrink the result to [1,3]. Taking max(lastEnd, currentEnd) keeps the merged interval correct when the later one is contained.
How do I prepare for this in 48 hours?+
Write the solution from scratch twice without looking. Then test on four cases: a single interval, fully nested intervals, touching endpoints, and unsorted input. That covers nearly every hidden test. It's a short problem, so don't over-study it.