Reported March 2024
Amazonarray

Merge Interval

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

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

Amazon brought back interval merging in March 2024, and it's the kind of problem that looks simple until you code it live. You're given overlapping intervals and need to merge them into non-overlapping ones. It's a classic array manipulation problem that trips candidates who skip the sort step or mishandle edge cases. StealthCoder can read the problem and feed you the merge logic in real time if you blank on the boundary conditions.

Pattern and pitfall

The pattern is straightforward: sort intervals by start time, then iterate through and merge whenever the current interval overlaps with the previous one. The trick is recognizing that 'overlap' means current.start <= prev.end, not just current.start < prev.end. Most candidates get the idea but mess up the merge operation itself, creating the wrong output interval bounds. The algorithm is O(n log n) due to sorting. This is a bread-and-butter array problem Amazon revisits often. If you nail the sort and the merge condition, you're done in under 10 minutes.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Merge Interval 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

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

Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Interval FAQ

Do I need to handle non-sorted input?+

Yes. The input is almost never pre-sorted. Sort by start time first, then by end time as a tiebreaker. That's step one. Skipping the sort is the #1 failure mode.

What counts as overlapping intervals?+

Interval [a, b] and [c, d] overlap if c <= b. If c equals b, they touch and must merge. Edge case: [1, 2] and [2, 3] should merge to [1, 3], not stay separate.

How hard is this for Amazon?+

Not hard algorithmically. Amazon uses it as a filter to check if you can code cleanly and handle boundaries. Most rejections come from bugs, not from not knowing the approach.

Can I do this in one pass without sorting?+

No. You must sort first. The entire algorithm hinges on processing intervals in order. Trying to merge unsorted intervals will fail.

What if intervals are identical?+

They merge into one. If input is [[1, 3], [1, 3]], output is [[1, 3]]. Your merge logic handles this automatically if you use <= for the overlap check.

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

OA at Amazon?
Invisible during screen share
Get it