Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Intersecting Time Intervals

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

Your question is Intersecting Time 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 task1 and task2, both being lists of sublists where each sublist represents [start_time, end_time], return a list of sublists containing the common intersection time [start, end].

Asked in the Round 1 : DSA stage. Coding question asked during DSA round.

Input and Output

Implement common_intersections(task1, task2). Each input is a list of sorted, non-overlapping closed intervals [start_time, end_time]. Return every non-empty intersection in chronological order. If two intervals touch at one endpoint, include that point, such as [2, 2].

Constraints

  • 0 <= len(task1), len(task2) <= 1000
  • Each interval has exactly two integers, [start_time, end_time]
  • 0 <= start_time <= end_time
  • Each list is sorted by start_time and contains non-overlapping intervals
  • Return intervals in chronological order

Function Signature

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