FastPrepMerge Intervals
Problems/Merge Intervals

Merge Intervals

Microsoft logoMicrosoft● MediumNEW GRADINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft onsite interview. The report names a variation of Merge Intervals but does not say what the variation is. Our version uses only the usual version with closed intervals. It is about 90% the same as the reported question.

Given an array of closed intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals.

Intervals that share an endpoint overlap. Return the non-overlapping intervals that cover every input interval, sorted by increasing start value.

Function

merge(intervals: int[][]) → int[][]

Examples

Example 1

intervals = [[1,3],[2,6],[8,10],[15,18]]return = [[1,6],[8,10],[15,18]]

Intervals [1,3] and [2,6] overlap and merge into [1,6]. The other intervals remain separate.

Example 2

intervals = [[1,4],[4,5]]return = [[1,5]]

The intervals share endpoint 4, so the closed intervals overlap.

Example 3

intervals = [[8,10],[1,4],[2,3],[15,18],[6,9],[3,7],[17,20],[12,12]]return = [[1,10],[12,12],[15,20]]

Sorting exposes two overlap chains: the intervals from [1,4] through [8,10] merge into [1,10], and the last two merge into [15,20].

Constraints

  • 1 <= intervals.length <= 10000
  • intervals[i].length == 2
  • -10^9 <= start_i <= end_i <= 10^9

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum Cars for Rental RequestsGoogle · OA · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Maximum Concurrent Processes (Bar Raiser Round)Amazon · PHONE SCREEN · ONSITE INTERVIEW
  • Meeting Scheduling SystemHevo Data · ONSITE INTERVIEW
  • Maximum Intervals Overlapping a Fixed-Length WindowBooking.com · ONSITE INTERVIEW
  • Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
  • Minimum Meeting Rooms with AssignmentsUber · PHONE SCREEN · ONSITE INTERVIEWUber interview questions
  • Peak Bike Demand IntervalsFaire · ONSITE INTERVIEW

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[][] merge(int[][] intervals) {
      // write your code here
    }
}
Checking account…