Reported October 2026
Limesorting

Merge Intervals

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

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

Lime put Merge Intervals in front of candidates in October 2026, and the detail that trips people is the shared endpoint rule. [1,4] and [4,5] count as overlapping and collapse into [1,5]. It's a sort-then-sweep problem on an array of closed intervals, and it's one of the most common patterns out there. If your OA lands in the next few days, you want the trick cold. Sort by start, walk once, extend or push. And if your brain locks up mid-assessment, StealthCoder runs invisibly as a safety net, reads the problem on screen, and gives you a working solution.

The problem

Given an array of closed intervals where intervals[i] = [start_i, end_i], merge every pair of overlapping intervals.
Return the non-overlapping intervals covering the same values, sorted by start time. Intervals that share an endpoint are considered overlapping.

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 first two intervals overlap and merge into [1,6].
Example 2
intervals = [[1,4],[4,5]]
return = [[1,5]]
Closed intervals sharing endpoint 4 overlap.
Example 3
intervals = [[8,10],[1,4],[2,3],[6,9],[3,7]]
return = [[1,10]]
After sorting, the intervals form one connected overlap chain.

Constraints
1 <= intervals.length <= 10000.
intervals[i].length == 2.
0 <= start_i <= end_i <= 100000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is sorting by start time first. Once sorted, any overlap can only happen with the last interval you kept. Keep a result list. For each interval, if its start is less than or equal to the last merged end, set that end to the max of both ends. Otherwise push it as a new interval. The pitfalls are small but fatal. Use <= not <, because Lime's statement says shared endpoints overlap. Use max for the end, since Example 3 has [2,3] sitting inside [1,4], and overwriting the end would shrink it. Don't mutate the input if you can avoid it. Complexity is O(n log n) from the sort, with n up to 10000, so that's comfortable. If you blank on the sweep logic during the live OA, StealthCoder is the hedge that surfaces the working code without the proctor seeing it.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

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

Lime 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?+

It's a medium on paper but easy once you know the move. Sort by start, then one pass. The whole solution is about ten lines. Most failures come from the edge conditions, not the idea. Practice writing it from memory once and you're fine.

What's the trick for the Lime version?+

Sort by start, then compare each interval to the last one in your result. Overlap means start <= last end. Merge by taking the max of the two ends. The Lime statement says shared endpoints count as overlapping, so the comparison must be inclusive.

What edge cases should I test?+

Test a single interval, two intervals sharing only an endpoint like [1,4] and [4,5], and a fully nested interval like [2,3] inside [1,4]. Also test unsorted input, as in Example 3, where everything chains into [1,10]. Those four cases catch nearly every bug.

What's the time and space complexity?+

Time is O(n log n) because of the sort, and the sweep after it is O(n). Space is O(n) for the output list, plus whatever your language's sort uses. With up to 10000 intervals, this runs comfortably without any optimization.

How do I prepare in 48 hours?+

Write this solution from scratch twice without looking. Then do one variant, like inserting a new interval into a sorted list. The sort-and-sweep pattern shows up in many interval questions, so those two reps cover most of what an OA could throw at you.

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

OA at Lime?
Invisible during screen share
Get it