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.
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 [].
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.
def find_earliest_slot(appointments, duration, work_start, work_end):