FastPrepFastPrep
Problem Brief

Generate Available Time Slots

FULLTIMEPHONE SCREEN
See Stripe online assessment and hiring insights

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 Description

Complete the function generateAvailableTimeSlots in the editor below.

generateAvailableTimeSlots has the following parameters:

  1. String startDate: inclusive lower datetime bound in YYYY-MM-DD HH:MM format
  2. String endDate: inclusive upper datetime bound in YYYY-MM-DD HH:MM format
  3. String[][] workingHours: each row is [weekday, windowStart, windowEnd], where weekday is 0 for Monday through 6 for Sunday

Returns

String[]: all valid 30-minute slots in chronological order.

1Example 1

Input
startDate = "2026-01-05 09:10", endDate = "2026-01-05 10:40", workingHours = [["0", "09:00", "12:00"]]
Output
["2026-01-05 09:30,2026-01-05 10:00", "2026-01-05 10:00,2026-01-05 10:30"]
Explanation

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.

2Example 2

Input
startDate = "2026-01-06 13:00", endDate = "2026-01-06 14:00", workingHours = [["1", "12:30", "14:30"]]
Output
["2026-01-06 13:00,2026-01-06 13:30", "2026-01-06 13:30,2026-01-06 14:00"]
Explanation

Only the two full 30-minute slots inside both the Tuesday working window and the requested datetime range are returned.

Constraints

Limits and guarantees your solution can rely on.

  • workingHours repeats weekly.
  • Only full 30-minute slots are emitted.
  • Output must be sorted chronologically.
public String[] generateAvailableTimeSlots(String startDate, String endDate, String[][] workingHours) {
    // write your code here
}
Input

startDate

"2026-01-05 09:10"

endDate

"2026-01-05 10:40"

workingHours

[["0", "09:00", "12:00"]]

Output

["2026-01-05 09:30", "2026-01-05 10:00", "2026-01-05 10:00", "2026-01-05 10:30"]

Sign in to submit your solution.