Compute Bookable Gaps From a Host's Blocked Date Ranges
Last updated: November 29, 2026
Quick Overview
A host's calendar has blocked night ranges from reservations, manual blocks, and synced external calendars, possibly overlapping and unsorted. Given a horizon and a minimum stay length, return every open gap inside the horizon that is long enough to book.
Airbnb
November 29, 20260
0
0 solved
A host's calendar has blocked night ranges from reservations, manual blocks, and synced external calendars, possibly overlapping and unsorted. Given a horizon and a minimum stay length, return every open gap inside the horizon that is long enough to book.
Airbnb shows availability by merging blocks from many sources, and short orphan gaps between bookings are a known host pain point. The interviewer uses this to check interval reasoning, half-open range conventions, and clipping to a window.
What the Interviewer Expects
- Agree on half-open [start, end) night ranges
- Sort by start and sweep with a cursor instead of building a merged list first
- Clip blocks that extend past the horizon
- Filter gaps shorter than the minimum stay
- Handle the gap after the last block
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 would you report gaps shorter than the minimum separately so hosts can discount them?
- If blocks are inserted one at a time, how do you keep gaps up to date efficiently?
- How does the answer change if the minimum stay differs by check-in weekday?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Blocks are integer day indexes as [start, end), meaning nights start..end-1 are taken. The horizon is [H0, H1). Return gaps [a, b) with b - a >= min_nights, in order. Overlapping and touching blocks m...
High-Level Design
Sort blocks by start. Keep cursor, the first night not yet known to be blocked. For each block, clip it to the horizon; if it starts after the cursor, the range [cursor, start) is free. Then advance...