runtime
99 / 500
question 99 Fundamentals Integration · medium

Free time in a meeting room

A room-booking screen shows when a meeting room is free. Bookings are (start, end) pairs of "HH:MM" times on one day, in any order, and they may overlap. Return the free gaps between day_start and day_end as (start, end) pairs in time order. A gap of zero minutes is not a gap.

Functionfree_slots(bookings, day_start="09:00", day_end="17:00")
bookingsa list of ("HH:MM", "HH:MM") tuples, unsorted, possibly overlapping, all inside the day
Returnsa new list of ("HH:MM", "HH:MM") free gaps in time order; the whole day when there are no bookings
Must notchange bookings
Examples
callfree_slots([('13:00', '14:30'), ('09:30', '10:00'), ('09:45', '11:00')])returns[('09:00', '09:30'), ('11:00', '13:00'), ('14:30', '17:00')]
callfree_slots([])returns[('09:00', '17:00')]
callfree_slots([('09:00', '17:00')])returns[]

Loading your progress…

Free time in a meeting room — Python practice · Runtime