Split stays across two listings
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Airbnb's coding round, last asked Feb 2026. It tests arrays, hash set and intervals.
A vacation rental site wants to offer split stays: when no single home is free for a guest's whole trip, the guest stays in one home first and then moves to another.
There are n listings, numbered 0 to n - 1. listings[i] is the list of days (integers) on which listing i is free. A guest asks for every day from start to end, inclusive.
Implement:
def split_stays(listings: list[list[int]], start: int, end: int) -> list[tuple[int, ...]]
Return every way to cover the whole range:
-
Single:
(i,)when listingiis free on every day fromstarttoend. -
Split stay:
(a, b)witha != bwhen there is a daytwithstart <= t < endsuch that listingais free on every day ofstart..tand listingbis free on every day oft+1..end. Pairs are ordered:(a, b)meansafirst. Report each pair once, even when several split days work.
Return the singles first, sorted, then the pairs, sorted. A one-day request has no split stays.
Constraints: 1 <= n <= 10^4, the range is at most 365 days long, and the days in each list are distinct but may be in any order. Aim for better than checking every pair at every split day.
Example 1
listings = [[3, 4], [5, 6, 7], [1, 2, 3, 4, 5, 6], [4, 5, 6]]
start = 3, end = 6
-> [(2,), (0, 1), (0, 2), (0, 3), (2, 1), (2, 3)]
Listing 2 covers days 3 to 6 on its own. Listing 0 covers days 3 and 4, and listings 1, 2 and 3 each cover days 5 and 6. Listing 2 can also come first, followed by listing 1 or 3. (1, 0) does not work, because listing 1 is not free on day 3.
Example 2
listings = [[10, 12], [11, 13]]
start = 10, end = 13
-> []
Each listing has a gap, and neither one's run of free days reaches the other's.
Clarifying questions
- Can listing days fall outside
start..end, and should they be ignored? - Does a split stay require the guest to move on a day boundary, staying in
athrough daytand inbfromt + 1? - If a listing covers the whole range alone, are its pairs with other listings still reported (example 1 shows
(2, 1))? - Is the output sorted by tuple order, with singles before pairs?
What a strong answer covers
- For each listing, computes in one pass over a set of its days how far it covers from
startwithout a gap (P[i]) and how early its free run reachingendbegins (S[i]). - A pair
(a, b)works when sometwithstart <= t < endhast <= P[a]andt + 1 >= S[b], so it is a comparison of two numbers per pair, not a check per split day. - Sorts listings by
Pand, for eachb, takes everya != bwithP[a] >= max(start, S[b] - 1); this is output-sensitive, since the answer can have up ton^2pairs. -
O(n * D)to build the runs for range lengthD, then sorting and output. - Tests both examples, a one-day request, and a listing that is free on every day.
Follow-ups
- Allow up to two moves (three listings).
- Rank the options, for example by price or by the fewest nights in the first home.
- Listings change availability often: keep the per-listing runs up to date.
Where it's asked
- Airbnb · Coding · Last asked Feb 202645 min · Live coding, one or two rounds, from the same pool as the screen
What it tests
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
