Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Write and Test a Function

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

Your question is Write and Test a Function. 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

Turing Mobile receives availability windows during which a mobile workflow may run. Given a collection of time intervals, merge every overlapping or adjacent interval so the result contains the fewest possible non-overlapping windows.

Formal Specification

Implement merge_mobile_windows(windows), where windows is a list of intervals. Each interval is represented as a two-element list [start, end], with integer time values and start <= end. Return a new list of merged intervals sorted by start. Intervals that overlap or touch, such as [1, 3] and [3, 5], must be merged into [1, 5]. Do not mutate the input list.

Constraints

  • 0 <= len(windows) <= 10^4
  • Each interval contains exactly two integers
  • -10^9 <= start <= end <= 10^9
  • Intervals that touch must be merged
  • The input list must not be mutated

Function Signature

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