Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge Overlapping Trade Intervals

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

Your question is Merge Overlapping Trade 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

At a trading firm like Jane Street, market activity is recorded as time intervals. Given a list of intervals representing active trading windows, merge all overlapping intervals and return the condensed list in ascending order.

Formal Specification

Implement a function that takes intervals, a list of lists where each element is [start, end] and start <= end. Return a new list of merged intervals, where any overlapping or touching intervals are combined into a single interval.

Constraints

  • 1 <= len(intervals) <= 10^4
  • intervals[i].length == 2
  • 0 <= intervals[i][0] <= intervals[i][1] <= 10^6
  • Intervals may be unsorted
  • Touching intervals should also be merged

Function Signature

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