PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates date/time arithmetic, interval and recurrence handling, edge-case reasoning, and test-case design within scheduling logic for generating fixed 30-minute slots from weekly working-hours and a requested datetime range.

  • hard
  • Stripe
  • Coding & Algorithms
  • Software Engineer

Generate Available 30-Minute Time Slots

Company: Stripe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are implementing availability generation for a scheduling service. Given: - `start_datetime`: the inclusive beginning of a requested date-time range. - `end_datetime`: the inclusive ending of the requested date-time range. - `working_hours`: a weekly recurring availability configuration. Each row contains: - `day_of_week`, such as Monday through Sunday. - `start_time`, a local time when availability begins on that weekday. - `end_time`, a local time when availability ends on that weekday. Generate every available 30-minute time slot that falls within both the requested range and the weekly working-hours configuration. Requirements: - A slot is represented by its start and end timestamps. - Each slot must be exactly 30 minutes long. - A slot must not start before `start_datetime`. - A slot must not end after `end_datetime`. - The first and last days of the requested range must be checked using their exact times, not just their dates. - Days without working-hours entries should produce no slots. - If a working-hours interval is shorter than 30 minutes, it should produce no slots. - Write tests covering normal multi-day ranges, partial first and last days, empty availability, and boundary cases where a slot exactly touches the requested start or end time. Implement a function that returns all valid 30-minute slots in chronological order.

Quick Answer: This question evaluates date/time arithmetic, interval and recurrence handling, edge-case reasoning, and test-case design within scheduling logic for generating fixed 30-minute slots from weekly working-hours and a requested datetime range.

You are implementing availability generation for a scheduling service. Given a requested date-time range and a weekly recurring working-hours configuration, return every valid 30-minute slot that fits inside both. Each working-hours row contains a day of the week, a start time, and an end time. For each working-hours interval, candidate slots begin at the interval's start time and repeat every 30 minutes. A slot is valid only if it is exactly 30 minutes long, starts at or after start_datetime, and ends at or before end_datetime. The returned slots must be in chronological order. Days without working-hours entries produce no slots, and working intervals shorter than 30 minutes produce no slots.

Constraints

  • start_datetime and end_datetime use the format 'YYYY-MM-DD HH:MM'.
  • start_datetime <= end_datetime.
  • 0 <= len(working_hours) <= 100.
  • working-hours intervals do not cross midnight; start_time <= end_time.
  • All times are local naive times with no timezone conversion required.
  • Candidate slots are generated every 30 minutes starting from each working-hours interval's start_time.

Examples

Input: ("2024-01-01 09:00", "2024-01-03 12:00", [("Monday", "09:00", "10:00"), ("Tuesday", "13:00", "14:00"), ("Wednesday", "11:00", "12:00")])

Expected Output: [["2024-01-01 09:00", "2024-01-01 09:30"], ["2024-01-01 09:30", "2024-01-01 10:00"], ["2024-01-02 13:00", "2024-01-02 13:30"], ["2024-01-02 13:30", "2024-01-02 14:00"], ["2024-01-03 11:00", "2024-01-03 11:30"], ["2024-01-03 11:30", "2024-01-03 12:00"]]

Explanation: The requested range spans Monday through Wednesday. Each listed working interval contributes two 30-minute slots, all inside the requested range.

Input: ("2024-01-01 09:15", "2024-01-02 10:45", [("Monday", "09:00", "10:30"), ("Tuesday", "10:00", "12:00")])

Expected Output: [["2024-01-01 09:30", "2024-01-01 10:00"], ["2024-01-01 10:00", "2024-01-01 10:30"], ["2024-01-02 10:00", "2024-01-02 10:30"]]

Explanation: The Monday 09:00-09:30 slot starts before the requested start time, so it is excluded. The Tuesday 10:30-11:00 slot ends after the requested end time, so it is excluded.

Input: ("2024-01-01 00:00", "2024-01-02 23:59", [("Wednesday", "09:00", "10:00")])

Expected Output: []

Explanation: The requested range covers Monday and Tuesday only. There are no working-hours entries for those days.

Input: ("2024-01-01 08:00", "2024-01-01 18:00", [("Monday", "09:00", "09:20")])

Expected Output: []

Explanation: The only working interval is shorter than 30 minutes, so it cannot produce a valid slot.

Input: ("2024-01-01 09:30", "2024-01-01 10:30", [("Monday", "09:00", "10:30")])

Expected Output: [["2024-01-01 09:30", "2024-01-01 10:00"], ["2024-01-01 10:00", "2024-01-01 10:30"]]

Explanation: A slot may start exactly at start_datetime and may end exactly at end_datetime. The 09:00-09:30 slot is excluded because it starts before the requested range.

Hints

  1. Iterate one calendar day at a time, find that day's weekday name, and look up matching working-hours intervals.
  2. For each working interval, generate 30-minute candidates and keep only those whose start and end are inside the requested range.
Last updated: Jun 22, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Assign Reviewers from Changed Files - Stripe (medium)
  • Generate Account Email Notifications - Stripe (medium)
  • Calculate Transaction Fees - Stripe (medium)
  • Build an Account Transfer Ledger - Stripe (medium)
  • Implement Validation and String Compression - Stripe (hard)