Find Bookable Therapy Slots From Availability and Booked Sessions
Last updated: November 29, 2026
Quick Overview
A therapist publishes availability windows (which may overlap) and already has booked sessions; return every start time on a 15 minute grid where a session of a given length fits entirely inside free time.
Headway
November 29, 20260
0
0 solved
A therapist publishes availability windows (which may overlap) and already has booked sessions; return every start time on a 15 minute grid where a session of a given length fits entirely inside free time.
Patients on Headway pick a time from a therapist's calendar, so the booking flow has to turn messy availability blocks and existing appointments into clean bookable slots. The interviewer looks for interval merging, a correct subtraction of busy time, and care with slot alignment.
What the Interviewer Expects
- Merge overlapping availability windows and overlapping bookings first
- Subtract busy intervals from free intervals with a linear sweep
- Align candidate starts to the grid rather than to arbitrary booking end times
- Only emit a slot if the full session duration fits
- State complexity in terms of windows, bookings and output slots
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How do you handle a therapist who wants a 10 minute buffer after each session?
- How would time zones and daylight saving transitions affect this if the therapist and patient are in different states?
- Two patients click the same slot at once. How do you prevent a double booking?
- How would you precompute this for a search page that shows the next open slot for thousands of therapists?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: availability windows and booked sessions as (start, end) datetimes, a session duration (for example 50 minutes), and a grid step (15 minutes). Output: sorted slot start times. Windows can ov...
High-Level Design
- Sort and merge each list. 2) Sweep both merged lists to produce free intervals (availability minus busy). 3) For each free interval, round its start up to the next grid point and step forward while...