FastPrepMerge Intervals
Problems/Merge Intervals

Merge Intervals

Lime logoLime● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Lime phone screen. The report names the well-known task of merging intervals. Here, interval ends are included and the output is sorted. This gives a fixed answer for every input.

You are given intervals where intervals[i] = [start_i, end_i]. Each interval includes both endpoints. Merge overlapping intervals.

Return the non-overlapping intervals covering the same values, sorted by start time. Intervals that share an endpoint are considered overlapping.

Function

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

Examples

Example 1

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

The first two intervals overlap and merge into [1,6].

Example 2

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

Closed intervals sharing endpoint 4 overlap.

Example 3

intervals = [[8,10],[1,4],[2,3],[6,9],[3,7]]return = [[1,10]]

After sorting, the intervals form one connected overlap chain.

Constraints

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

Similar questions at other companies

  • Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
  • Finish Time of Fixed-Length CPU TasksGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Maximum Concurrent Processes (Bar Raiser Round)Amazon · PHONE SCREEN · ONSITE INTERVIEW
  • Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
  • Minimum Rooms for Meeting IntervalsOYO Rooms · PHONE SCREEN
  • Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
  • Majority Labels over Audio IntervalsNooks · PHONE SCREEN
  • Meeting Rooms IIUber · PHONE SCREENUber interview questions
  • Query Weekly Store Opening HoursApple · PHONE SCREENApple interview questions
See Lime hiring insights
Saved
class Solution {
    public int[][] merge(int[][] intervals) {
        // Write your code here.
    }
}
Checking account…