Generate Available Time Slots
Learn this problemProblem statement
You are given a datetime range [startDate, endDate] and a weekly recurring working-hours configuration.
Generate every available 30-minute slot that is fully contained in the range and also lies inside one of the working-hour windows for the corresponding weekday.
Each slot is represented as a string "start,end", where the start and end timestamps are separated by a comma.
The first and last days must be validated using the exact time boundaries: a slot is valid only when slotStart >= startDate and slotEnd <= endDate.
Function
generateAvailableTimeSlots(startDate: String, endDate: String, workingHours: String[][]) → String[]Complete the function generateAvailableTimeSlots in the editor below.
generateAvailableTimeSlots has the following parameters:
String startDate: inclusive lower datetime bound inYYYY-MM-DD HH:MMformatString endDate: inclusive upper datetime bound inYYYY-MM-DD HH:MMformatString[][] workingHours: each row is[weekday, windowStart, windowEnd], whereweekdayis0for Monday through6for Sunday
Returns
String[]: all valid 30-minute slots in chronological order.
Examples
Example 1
startDate = "2026-01-05 09:10"endDate = "2026-01-05 10:40"workingHours = [["0", "09:00", "12:00"]]return = ["2026-01-05 09:30,2026-01-05 10:00", "2026-01-05 10:00,2026-01-05 10:30"]The 09:00-09:30 slot starts before the allowed range, and the 10:30-11:00 slot ends after the allowed range. The two middle 30-minute slots are fully contained.
Example 2
startDate = "2026-01-06 13:00"endDate = "2026-01-06 14:00"workingHours = [["1", "12:30", "14:30"]]return = ["2026-01-06 13:00,2026-01-06 13:30", "2026-01-06 13:30,2026-01-06 14:00"]Only the two full 30-minute slots inside both the Tuesday working window and the requested datetime range are returned.
Constraints
workingHoursrepeats weekly.- Only full 30-minute slots are emitted.
- Output must be sorted chronologically.