Time Slot Generator from Weekly Working Hours
Updated
Problem 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 Phone Screen questions
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- CSV Row SerializerMercor · PHONE SCREENMercor interview questions
- Host Log ParserVerkada · PHONE SCREENVerkada interview questions
- Length-Prefixed String CodecSnowflake · PHONE SCREENSnowflake interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- HTTP Status Log SummaryApple · PHONE SCREENApple interview questions
- JSON Identity VerificationKikoff · PHONE SCREENKikoff interview questions
- Alert After Repeated Column Threshold BreachesMeta · PHONE SCREENMeta interview questions
- Serialize a Nested Dictionary as JSONGoogle · PHONE SCREENGoogle interview questions
- Render a Source-Backed Markdown SubsetSamsara · PHONE SCREENSamsara interview questions
Stripe interview experiences
- Stripe New Grad SWE OA and Phone Screen: 2 Experiences
- Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
- Stripe SWE Intern Linked Merchants Team Screen: 1 Experience
- Stripe OA: What It Tests (2026)
- Stripe SWE Onsite over Two Days: 1 Experience
- Stripe New Grad SWE Phone Screen and Onsite: 2 Experiences