Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge Overlapping Intervals

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

Your question is Merge Overlapping 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 pair [start, end], merge all overlapping intervals and return a new array of non-overlapping intervals that covers the same ranges. The output may be returned in any order, but an efficient solution should exploit sorting.

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start <= end <= 10^4
  • Intervals may appear in any order

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