AO
Back

Merge Intervals, Then Return Every Overlapping Interval

Also reported as LeetCode 56

CodingOnsiteLast reported April 2026Medium Frequency

Problem Overview

The round: Merge Intervals (LeetCode 56) in onsite rounds. Four reports between November 2025 and April 2026. Three name LeetCode 56 as asked, one of them in a Microsoft AI loop. A hiring-event round asked a variant: output every interval that overlaps. That candidate expected to sort and scan. Two graded parts: the merge, then the variant. They were reported as separate problems; no report asks the variant after LeetCode 56, so putting them on one page is our choice.

Intervals are [start, end] lists of ints with start <= end.

Part 1 — merge overlapping intervals (LeetCode 56)

def merge(intervals: list[list[int]]) -> list[list[int]]: ...
  • Merge all overlapping intervals and return the result sorted by start. LeetCode's rules: intervals that touch ([1,4] and [4,5]) overlap. The input may be unsorted.

Part 2 — every interval that overlaps another

def overlapping_intervals(intervals: list[list[int]]) -> list[list[int]]: ...
  • Return each input interval that overlaps at least one other input interval, sorted by start. Intervals that overlap nothing are left out. For [[1,3],[2,6],[8,10],[15,18]] the answer is [[1,3],[2,6]].
  • Must be faster than comparing every pair: the tests include 200,000 intervals. That size is ours, not reported.

Notes: the report gives the variant in one line ("output all the overlapping intervals"), so this page reads it as the intervals that overlap some other interval. Two other readings exist: every overlapping pair, or the overlapping stretches themselves (the intersections). Ask which one is wanted; the first is sketched below as an ungraded variant. Whether touching intervals count in Part 2 is not reported. The reference counts them, as Part 1 does, and no Part 2 test has intervals that only touch. The output order in Part 2 is ours; the tests sort before comparing. The function names are ours.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 1
Trade-off discussion

Variant: instead of merging, output every interval that overlaps.

Probes for: reported, hiring-event onsite; clarify whether it means intervals, pairs or overlapping stretches

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
For the variant, merge while recording which original intervals form each group, then return the members of groups with two or more intervals.—

What Reports Emphasize

Common mistakes: Not sorting first, or replacing the merged end instead of taking the larger one. In the variant, checking each interval only against its sorted neighbour: a long interval can overlap one several places later.

What candidates did: The candidate who got the variant planned to sort, scan once, then merge. In the round before it, they had to run tests.

Edge cases to test: Touching intervals ([1,4], [4,5]). One interval containing others. Unsorted input. A single interval. In the variant: an interval that overlaps nothing, and two copies of the same interval.

Practice

Write your own against 7 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Microsoft with friends?

Send them this page. It is free to read, no account needed.

More Microsoft Questions

Free preview

Every question in the Microsoft catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 39 Microsoft questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Microsoft · Coding · Reported 4× across candidate reports
Is this helpful?