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.
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.
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.
def find_narrowest_slot(window_start, window_end, schedules):