Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Solve a Data Structure Problem

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

Your question is Solve a Data Structure Problem. 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

QualityKiosk's test execution dashboard receives time windows during which automated tests run. Given a collection of inclusive integer intervals, merge every pair of overlapping or directly adjacent windows and return the resulting non-overlapping intervals in chronological order.

Formal Specification

Implement merge_test_windows(intervals). The input intervals is a list of two-element lists, where each interval is [start, end] and start <= end. Return a new list of two-element lists representing the merged windows. The input may be unsorted. Intervals [a, b] and [b + 1, c] are considered directly adjacent and must also be merged.

Constraints

  • 0 <= len(intervals) <= 10^5
  • Each interval contains exactly two integers
  • -10^9 <= start <= end <= 10^9
  • Intervals that overlap or are adjacent must be merged

Function Signature

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