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.
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.
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.
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.
workingHoursrepeats weekly.- Only full 30-minute slots are emitted.
- Output must be sorted chronologically.
- Account Balance Manager Part 3 - Platform CoverageONSITE INTERVIEW · Seen Jun 2026
- BitFont Part 3 - Decode Run-Length-Encoded RowsONSITE INTERVIEW · Seen Jun 2026
- Record Linkage Part 3 - Full Connected ComponentPHONE SCREEN · Seen Jun 2026
- Shipping Cost Calculator Part 3 - Mixed Fixed/Incremental TiersONSITE INTERVIEW · Seen Jun 2026
- Transaction Fee Calculator - Per-Merchant Volume DiscountPHONE SCREEN · Seen Jun 2026
- Account Balance Manager Part 2 - Reject OverdraftsONSITE INTERVIEW · Seen Jun 2026
- BitFont Part 2 - Render a WordONSITE INTERVIEW · Seen Jun 2026
- Factory Cost - Min-Cost Path Skipping One StagePHONE SCREEN · Seen Jun 2026
public String[] generateAvailableTimeSlots(String startDate, String endDate, String[][] workingHours) {
// write your code here
}