Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge Overlapping Time Windows

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

Your question is Merge Overlapping Time Windows. 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 a list of closed intervals windows, where each interval is a pair [start, end] with start <= end, merge all overlapping intervals and return the resulting list sorted by start time. Two intervals overlap if the next interval's start is less than or equal to the current merged interval's end.

Constraints

  • 1 <= len(windows) <= 10^5
  • 0 <= start <= end <= 10^9
  • Each interval is a list of exactly two integers

Function Signature

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