Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge Overlapping Sorted Intervals

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Merge Overlapping Sorted Intervals. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an array of intervals intervals, where each interval is a two-element array [start, end], merge all overlapping intervals and return a new array of non-overlapping intervals sorted by their start time. Each returned interval should cover the full range of all intervals merged into it.

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start <= end <= 10^4
  • The input intervals are not guaranteed to be sorted

Function Signature

def merge_intervals(intervals):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output