Merge Intervals
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reported this one in August 2026, and it's Merge Intervals, the classic. If your OA invite is sitting in your inbox, here's the good news: it reduces to sort by start, then sweep once and extend the last interval whenever the next one touches it. That's it. The tricky part is the small details, like closed endpoints counting as overlap. If you blank mid-assessment, StealthCoder runs invisibly as a desktop overlay and can hand you the solution in real time. But you probably won't need it once you see the shape of this.
The problem
Given an array intervals where intervals[i] = [start_i, end_i], merge every pair of overlapping closed intervals. Return the non-overlapping intervals that cover exactly the same values, ordered by increasing 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]] The closed intervals [1,3] and [2,6] overlap, so they merge into [1,6]. Example 2 intervals = [[1,4],[4,5]] return = [[1,5]] Closed intervals that share an endpoint overlap. Constraints 1 <= intervals.length <= 10^4 intervals[i].length = 2 0 <= start_i <= end_i <= 10^4
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is sorting. Once intervals are ordered by start, any overlap can only happen with the most recent merged interval, so you never look backward. Keep a result list. For each interval, if its start is less than or equal to the last result's end, set that end to the max of both ends. Otherwise push it as new. The pitfalls: using strict less-than instead of less-than-or-equal, which breaks Example 2 where [1,4] and [4,5] must become [1,5]. Forgetting the max, so [1,10] followed by [2,3] shrinks wrongly. And mutating the input in a way you didn't intend. Complexity is O(n log n) for the sort and O(n) for the sweep. With n up to 10^4, that's trivial. If your head goes blank on the comparator or the edge case, StealthCoder is the hedge during the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
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 Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Merge Intervals FAQ
How hard is Merge Intervals really for the Bloomberg OA?+
Medium on paper, easy once you know the pattern. It's sort plus one linear pass. Most failures come from edge cases, not the idea. If you've seen it once, you can write it in under ten minutes.
What's the one trick I need?+
Sort by start first. After that, you only compare each interval to the last one in your result. If start is less than or equal to that last end, merge by taking the larger end. Otherwise append a new interval.
Do touching intervals like [1,4] and [4,5] merge?+
Yes. The problem says closed intervals sharing an endpoint overlap, so Example 2 returns [[1,5]]. Use start <= lastEnd in your condition, not strict less-than. This is the most common wrong answer.
What's the time and space complexity?+
Time is O(n log n) because of sorting, and the merge pass is O(n). Space is O(n) for the output, plus whatever your sort uses. With up to 10^4 intervals, performance won't be an issue.
How do I prepare in 48 hours?+
Write this from scratch twice without looking. Then test on nested intervals like [1,10],[2,3], a single interval, and unsorted input. Also do a couple of variants like Insert Interval so the sweep logic feels automatic.