← Questions
Free 30-minute time slots
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Apr 2026. It tests intervals, scheduling and sorting.
Build the slot generator behind a booking page. A person has weekly working hours, for example Monday 09:00 to 12:00. Given a requested date-time range, return every 30-minute slot in it that falls fully within working hours.
Interface
Unless you agree on a different interface with the interviewer, assume:
free_slots(working_hours: dict[str, list[tuple[str, str]]], start: datetime, end: datetime) -> list[datetime]-
working_hoursmaps a weekday ("MON"to"SUN") to intervals("HH:MM", "HH:MM"), start inclusive and end exclusive. - A slot starts on the hour or the half hour, lasts 30 minutes, and must lie fully inside both the requested range and one working interval. Return slot start times in order.
Example
working_hours = {"MON": [("09:00", "12:00")], "TUE": [("13:00", "15:00")]}
free_slots(working_hours, 2026-10-19 10:15, 2026-10-20 14:00)
-> [Mon 10:30, Mon 11:00, Mon 11:30, Tue 13:00, Tue 13:30]
# 10:00 starts before the range; Tuesday 14:00-14:30 ends after it
(2026-10-19 is a Monday.)
Constraints
- The range can span several weeks.
- All times are in one time zone for Part 1.
Clarifying questions
- Must slots start on :00 and :30, or anywhere a 30-minute window fits?
- Can one weekday have several intervals, and can an interval cross midnight?
- Is the range end inclusive or exclusive?
- Which time zone are the working hours in, and how should daylight saving changes behave?
What a strong answer covers
- Walking day by day over the range and intersecting each day's intervals with it, rather than testing every half hour of every week.
- Rounding the first candidate up to the next half hour and stopping at the last slot that fits.
- Edge cases: a range that starts mid-slot, empty days, back-to-back intervals, ranges shorter than 30 minutes.
- A list of test cases written before the code, covering each of those edges.
Follow-ups
- Remove slots that overlap existing meetings, given as a list of busy intervals. With meetings Mon 11:00-11:30 and Tue 13:10-13:40, the example returns
[Mon 10:30, Mon 11:30]. - Working hours are in the host's time zone and the range in the guest's, across a daylight saving change.
- Add a buffer of 10 minutes before and after every meeting.
- Find slots where several people are all free.
Where it's asked
- Stripe · Technical phone screen · Last asked Apr 202660 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
