← Questions

Split stays across two listings

0
AirbnbCodingLast asked Feb 2026

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 listing i is free on every day from start to end.
  • Split stay: (a, b) with a != b when there is a day t with start <= t < end such that listing a is free on every day of start..t and listing b is free on every day of t+1..end. Pairs are ordered: (a, b) means a first. 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 a through day t and in b from t + 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 start without a gap (P[i]) and how early its free run reaching end begins (S[i]).
  • A pair (a, b) works when some t with start <= t < end has t <= P[a] and t + 1 >= S[b], so it is a comparison of two numbers per pair, not a check per split day.
  • Sorts listings by P and, for each b, takes every a != b with P[a] >= max(start, S[b] - 1); this is output-sensitive, since the answer can have up to n^2 pairs.
  • O(n * D) to build the runs for range length D, 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

arrays · hash set · intervals

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