Problem · Array

Merge Intervals

Learn this problem
MediumRobloxPHONE SCREEN
See Roblox hiring insights

Problem statement

Source note, June 26, 2026: Please ignore this question for now, as it may have source issues. If you still want to practice it, treat it as a rough draft rather than a reliable source-backed problem. I will investigate and clean it up later, but this may take a while. Sorry for the inconvenience, and thank you so much for your understanding. You are the best! 🐥

You are given an array of intervals where intervals[i] = [start_i, end_i].

Merge every pair of overlapping intervals and return an array of non-overlapping intervals that covers all intervals in the input.

Two intervals overlap if they share at least one common point. For example, [1, 2] and [3, 4] do not overlap, but [1, 2] and [2, 3] do overlap.

You may return the merged intervals in any order.

Function

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

Examples

Example 1

intervals = [[1, 3], [1, 5], [6, 7]]return = [[1, 5], [6, 7]]
The intervals [1, 3] and [1, 5] overlap, so they merge into [1, 5]. The interval [6, 7] does not overlap with that merged interval.

Example 2

intervals = [[1, 2], [2, 3]]return = [[1, 3]]
The two intervals share point 2, so they overlap and merge into [1, 3].

Constraints

  • 1 <= intervals.length <= 1000
  • intervals[i].length == 2
  • 0 <= start_i <= end_i <= 1000

More Roblox problems

drafts saved locally
public int[][] mergeIntervals(int[][] intervals) {
  // write your code here
}
intervals[[1, 3], [1, 5], [6, 7]]
expected[[1, 5], [6, 7]]
checking account