Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Two Sigma interview question

Merge all overlapping intervals in a list

Company:
Two Sigma
Round:
Onsite
Type:
Coding
Difficulty:
Medium
Reported:
June 2, 2026

Problem

Given a list of closed intervals [start, end], merge every group of overlapping intervals into one interval and return the merged intervals sorted by start. Two intervals overlap when they share at least one point, so [1, 3] and [3, 5] merge into [1, 5].

Example 1

Input: intervals = [[1,3],[8,10],[2,6],[15,18]]
Output: [[1,6],[8,10],[15,18]]

[1,3] and [2,6] overlap and become [1,6]; the others stand alone.

Example 2

Input: intervals = [[1,4],[4,5]]
Output: [[1,5]]

Touching endpoints count as overlapping.

Constraints

  • 0 <= len(intervals) <= 10^5
  • -10^9 <= start <= end <= 10^9
  • The input is not necessarily sorted

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern