Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Narrowest Available Slot From Dates
00:00
5 left

Narrowest Available Slot From Dates

MediumPython

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):
Interviewer

Your question is Narrowest Available Slot From Dates. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.