FastPrepMerge Intervals
Problems/Merge Intervals

Merge Intervals

Patreon logoPatreon● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Six Patreon interview reports from November 2021 to February 2022 name this task. A Backend/Fullstack Engineer candidate (November 2021) got it in a one-hour technical screen. A Senior Fullstack Engineer candidate (January 2022) had it as the first of two questions in a 45-minute technical interview, with a rate limiter second; we count that interview as a phone screen because the report describes no later round. A Senior Software Engineer candidate (January 2022) met it next to an API rate limiter in the coding round of an onsite, and a reply to that post (February 2022) says the same two questions came up in the replier's phone screen. Another Senior Software Engineer candidate (February 2022) got it second in a one-hour coding call, after an LRU cache, and ran out of time on it; we count that call as a phone screen because the report gives no sign of a final round. A February 2022 phone-screen report puts it first, before a rate limiter, and says the coding pad held just an empty Java main method, so the candidate built the input and printed the output by hand. The reports give no input sizes or value ranges and do not say what happens when one interval ends exactly where another begins. Our choices for this exercise: an interval covers its first and last points too, so a pair that ends at the exact point where another starts is joined with it; the answer is listed by start; all limits are ours; and a function receives the intervals and returns the combined list instead of reading input and printing.

The input intervals is a list of pairs. A pair [start, end] has two integers with start <= end and covers each point between them, including start and end themselves. Pairs appear in no particular order.

Whenever two intervals have a point in common, join them into a single interval that covers both. Sharing only an endpoint is enough: [1, 2] and [2, 3] join into [1, 3]. Keep joining while any two intervals still have a point in common.

Return the joined intervals ordered by start, lowest first.

Function

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

Examples

Example 1

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

In order of start the pairs are [1, 3], [2, 5], [4, 7] and [9, 10]. [1, 3] and [2, 5] have the points 2 to 3 in common, so they become [1, 5]. That one shares 4 to 5 with [4, 7], giving [1, 7]. [9, 10] begins after 7, so it remains separate.

Example 2

intervals = [[3, 6], [10, 12], [6, 8]]return = [[3, 8], [10, 12]]

[3, 6] ends at 6, the same point where [6, 8] begins. Meeting at one end counts as overlapping, so the two become [3, 8]. [10, 12] has no point in common with it.

Example 3

intervals = [[5, 12], [13, 15], [6, 8], [9, 9]]return = [[5, 12], [13, 15]]

[6, 8] and the single point [9, 9] lie inside [5, 12], so they add nothing and [5, 12] keeps its end 12. [13, 15] starts at 13, after 12, so the two have no point in common and both stay.

Constraints

  • 1 <= intervals.length <= 104
  • intervals[i].length == 2
  • 0 <= intervals[i][0] <= intervals[i][1] <= 104

More Patreon Phone Screen questions

  • Sliding-Window API Rate LimiterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Employee Importance from a DictionaryPHONE SCREEN · Seen Feb 2026
  • Uniform Random Number from Coin TossesPHONE SCREEN · Seen Feb 2026
  • Wordle Guess CheckerPHONE SCREEN · Seen Jan 2026
  • Org Chart Report CountsPHONE SCREEN · Seen Dec 2025
  • Format the Missing Numbers from 1 to 99PHONE SCREEN · Seen Sep 2025
  • Pythagorean Triplets in an ArrayPHONE SCREEN · Seen Oct 2024
  • LRU Cache with TTLPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Password GeneratorPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • JSON ParserPHONE SCREEN · Seen Jun 2021

Similar questions at other companies

  • Top Ten Largest FilesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Valid Triangle NumberBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Travelers per Consecutive City TripletUber · ONSITE INTERVIEWUber interview questions
  • Implement QuicksortByteDance · PHONE SCREENByteDance interview questions
  • Merge Overlapping IntervalsShnoor International · ONSITE INTERVIEW
  • Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
All Patreon interview questionsSee Patreon hiring insights
Saved
class Solution {
    public int[][] merge(int[][] intervals) {
        // Write your code here.
    }
}
Checking account…