Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Narrowest Available Slot From Dates

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

Your question is Narrowest Available Slot From Dates. 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

Headway needs to identify the narrowest open time slot for scheduling an appointment. Given a scheduling window and existing appointment intervals, return the shortest positive-length gap that is fully available. If multiple gaps have the same duration, return the earliest one.

Formal Specification

Implement find_narrowest_slot(window_start, window_end, schedules). window_start and window_end are strings in YYYY-MM-DDTHH:MM format. schedules is a list of two-element lists, where each inner list contains a busy interval [start, end] in the same format. Return the available interval as [start, end], using the same format, or return [] if no positive-length gap exists.

Appointments may overlap or touch. Treat touching intervals as one continuous busy period. All schedules are within the scheduling window, and every interval has start < end.

Constraints

  • 0 <= len(schedules) <= 10^5
  • Times use minute precision and the format YYYY-MM-DDTHH:MM
  • window_start < window_end
  • Every schedule satisfies start < end
  • Every schedule lies fully within the scheduling window

Function Signature

def find_narrowest_slot(window_start, window_end, schedules):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output