Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Most Efficient Available Slot

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

Your question is Find Most Efficient Available Slot. 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 Scheduling receives a provider's booked appointment intervals and must find the earliest available slot within a working window. Given the required appointment duration, return the earliest slot that does not overlap any booking.

Booked intervals may overlap or be adjacent, and the input is not sorted. Treat times as integer minute offsets, with intervals represented as [start, end), meaning start is occupied and end is available.

Formal Specification

Implement find_available_slot(booked, day_start, day_end, duration).

  • booked is a list of two-element integer lists [start, end].
  • day_start and day_end define the provider's available working window.
  • duration is the required appointment length in minutes.
  • Return [slot_start, slot_end] for the earliest valid slot, or [] if none exists.
  • A slot may start at day_start or end exactly at day_end.

Constraints

  • 0 <= len(booked) <= 10^5
  • 0 <= day_start < day_end <= 10^9
  • 1 <= duration <= day_end - day_start
  • Every booking satisfies day_start <= start < end <= day_end
  • Return the earliest valid slot, not every valid slot

Function Signature

def find_available_slot(booked, day_start, day_end, duration):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output