This question evaluates a candidate's ability to reason about time-interval data and temporal normalization, testing competencies in interval manipulation, conflict detection, and algorithmic problem-solving for scheduling contexts.
You are building an API to show which time slots are available for booking at a restaurant.
You are given:
Opening hours and reservations are provided in a nested dictionary structure.
Assume times are in the same timezone and represented as minutes-from-midnight or as HH:MM strings that can be converted to minutes.
hours[day] = [open_time, close_time]
reservations[day] = [[start1, end1], [start2, end2], ...]
Example shape:
hours = {
"Mon": ["11:00", "22:00"],
"Tue": ["11:00", "22:00"],
}
reservations = {
"Mon": [["12:00", "12:30"], ["18:00", "19:15"]],
"Tue": [],
}
Write a function that returns, for each day, the list of available time intervals within opening hours that are not blocked by existing reservations.
Clarify/handle these cases:
Return a nested dictionary:
available[day] = [[free_start1, free_end1], [free_start2, free_end2], ...]
(Optionally, if a booking duration D minutes is provided, return only free intervals of length >= D, or return discrete start times valid for a D-minute reservation—state your choice.)