Reported September 2024
JP Morgansorting

Get Merged Intervals

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

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

JP Morgan's 'Get Merged Intervals' problem hit the OA circuit in September 2024, and it's a straightforward interval-merging task that trips up candidates who overthink the sort. You're given a list of intervals, some overlapping, and you need to return them merged into non-overlapping ranges. The pattern is old and well-known, but the implementation matters: sort by start time, then iterate once, tracking the current interval's end. Miss the edge case where intervals are already sorted or where one interval swallows another, and you'll fail test cases silently. StealthCoder is your safety net if the logic blanks mid-OA.

Pattern and pitfall

The core trick is sorting: intervals must be sorted by their start position. Once sorted, merge is a single pass. Maintain a 'current' interval. For each new interval, if it overlaps the current one (new start is less than or equal to current end), extend the current end to max(current end, new end). Otherwise, save the current interval and move to the new one. The common pitfall is forgetting to handle the last merged interval after the loop exits. Another trap: assuming input is already sorted (it usually isn't). The pattern is straightforward sorting and greedy merge, not dynamic programming or binary search. StealthCoder will flag this as a merge-intervals variant and show you the exact template in real time if you blank on the loop logic.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Get Merged 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. If you're reading this with an OA window open, you're who this was built for.

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

JP Morgan reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Get Merged Intervals FAQ

Is this just LeetCode Merge Intervals with a different name?+

Yes, functionally identical. JP Morgan uses the same problem structure. Sort by start, iterate once, merge greedily. The OA won't trick you with tricky overlaps; it tests whether you can code the sort and merge without off-by-one errors.

What's the gotcha JP Morgan usually bakes in?+

Edge cases: empty input, single interval, all overlapping, none overlapping, and intervals where one fully contains another. The last one catches people who only check if new start is less than current end. You need max(current end, new end) for the merge.

Do I need to handle negative coordinates or weird data types?+

The problem statement isn't provided, so assume standard integers and coordinate ranges. JP Morgan typically doesn't add complexity like floats or custom objects for this pattern. Keep it simple and don't over-engineer.

How much time should I spend on this if it appears in my OA?+

5-7 minutes max to write and test. Sort, loop, merge. If you're taking longer, you're overthinking. The pattern is a classic, and execution is the only variable. Trust your muscle memory.

If I blank on the merge loop, what's the minimal fallback?+

Sort intervals by start. Loop through. If current interval overlaps the last merged one, extend its end. Otherwise, add it to results. That's the skeleton. StealthCoder will feed you the exact code if you freeze.

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

OA at JP Morgan?
Invisible during screen share
Get it