Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Best Available Appointment

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

Your question is Best Available Appointment. 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's scheduling experience needs to find the earliest time a requested appointment can fit within a provider's working window. Given existing appointments, a requested duration, and the working-day boundaries, return the earliest available appointment interval.

Appointments use half-open intervals: [start, end) includes start but not end. Existing appointments may overlap or touch, and they are provided in arbitrary order. Merge them before searching for a gap. The returned slot must be fully inside the working window and must not overlap any existing appointment. If no slot is large enough, return [].

Formal Specification

Implement find_earliest_slot(appointments, duration, work_start, work_end), where appointments is a list of two-element integer lists [start, end], duration, work_start, and work_end are integer minutes from midnight. Return a two-element list [slot_start, slot_end], or an empty list when no slot exists. The best slot is the earliest valid slot, so return the first possible start time.

Constraints

  • 1 <= len(appointments) <= 10^5
  • Appointments are two-element lists [start, end]
  • 0 <= work_start < work_end <= 1440
  • work_start <= start < end <= work_end
  • 1 <= duration <= work_end - work_start
  • All times and durations are integer minutes

Function Signature

def find_earliest_slot(appointments, duration, work_start, work_end):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output