Problem · Simulation
Time Slot Generator from Weekly Working Hours
Learn this problemProblem statement
Generate every 30-minute appointment slot that falls inside a datetime range and inside that day's working hours.
Inputs:
startDateandendDate: datetime strings"YYYY-MM-DD HH:MM"sharing one timezone.workingHours: aString[]where each entry is"day_of_week,start_time,end_time";day_of_weekis0=Monday ...6=Sunday and the times are"HH:MM". This table repeats every week.
Output: a String[] of slots sorted by start time, each formatted as "YYYY-MM-DD HH:MM|YYYY-MM-DD HH:MM" (start and end joined by |).
Slot rules:
- Each slot is exactly 30 minutes, generated in 30-minute increments counted from a working interval's start time.
- A slot must be fully inside a working interval for that weekday:
slot_start >= work_startandslot_end <= work_end. - A slot start must be
>= startDateand a slot end must be<= endDate. A slot ending exactly atendDateis included; compare full datetimes, not just the date, on the boundary days. - If
startDate >= endDate, return an empty list. - Overlapping or touching working intervals on the same weekday are merged so no duplicate slot is emitted (treat touching intervals like
...12:00then12:00...as one).
Function
generateTimeSlots(startDate: String, endDate: String, workingHours: String[]) → String[]Examples
Example 1
startDate = "2026-03-02 10:15"endDate = "2026-03-04 11:45"workingHours = ["0,09:00,12:00", "1,13:00,14:00", "2,10:00,12:00"]return = ["2026-03-02 10:30|2026-03-02 11:00", "2026-03-02 11:00|2026-03-02 11:30", "2026-03-02 11:30|2026-03-02 12:00", "2026-03-03 13:00|2026-03-03 13:30", "2026-03-03 13:30|2026-03-03 14:00", "2026-03-04 10:00|2026-03-04 10:30", "2026-03-04 10:30|2026-03-04 11:00", "2026-03-04 11:00|2026-03-04 11:30"]2026-03-02 is a Monday (dow 0, 09:00-12:00). The 10:00->10:30 slot is dropped because it starts before startDate 10:15; the first emitted Monday slot is 10:30->11:00. Tuesday (dow 1) gives 13:00-14:00 slots. Wednesday (dow 2, 10:00-12:00): the 11:30->12:00 slot is dropped because it ends after endDate 11:45, so the last emitted slot is 11:00->11:30.
Example 2
startDate = "2026-03-02 09:01"endDate = "2026-03-02 09:59"workingHours = ["0,09:00,10:00"]return = []Monday interval 09:00-10:00. The 09:00->09:30 slot starts before startDate 09:01, so it is excluded. The 09:30->10:00 slot ends at 10:00 which is after endDate 09:59, so it is also excluded. No slot fully fits the range.
Constraints
startDateandendDateare"YYYY-MM-DD HH:MM"in one shared timezone.- Each
workingHoursrow is"day_of_week,start_time,end_time"withday_of_weekin0..6andstart_timestrictly beforeend_time. - Each slot is exactly 30 minutes and fully contained in a working interval.
- Slot start
>= startDate; slot end<= endDate(a slot ending exactly atendDateis included). - Return
[]ifstartDate >= endDate. - Merge overlapping/touching same-weekday intervals before generating slots.
More Stripe problems
- Group Linked Merchant RecordsPHONE SCREEN · Seen Jul 2026
- Invoice / Payment ReconciliationPHONE SCREEN · Seen Jul 2026
- Incident MonitorOA · Seen Jul 2026
- Merchant Fraud Risk ScoringOA · Seen Jul 2026
- WebSocket Load Balancer — Basic Load Balancing (Part 1)OA · Seen Jul 2026
- Rule-Driven Transaction Fraud DetectionOA · PHONE SCREEN · Seen Jul 2026
- Deployment Window SchedulerOA · Seen Jul 2026
- Directly Linked UsersOA · Seen Jun 2026