Airbnb CodingFree previewFree
Two-Listing Split Stay
Last asked
Problem
Given a set of Airbnb listings, each with a list of available days, and a requested date range, return every pair of two distinct listings whose combined availability covers the range with no overlap (the first listing covers a contiguous prefix, the second covers the remainder).
- Implement an API endpoint that takes
(listings: Map<String, List<Int>>, startDate: Int, endDate: Int)and returns all unordered pairs of listing names that can form a valid split stay. - A split is valid when listing A covers some contiguous prefix
[start, k]and listing B covers the suffix[k+1, end]; both halves must be fully contained in the respective listing's availability set. - Each pair appears once. If a single listing already covers the full range, that's a degenerate result — clarify with the interviewer whether to include single-listing solutions.
- Return order is unspecified; many candidates choose lexicographic to make tests stable.
Input
Curated: API endpoint (listings: Map<String, List<Int>>, startDate: Int, endDate: Int). OJ "Find Split Stays for Airbnb Listings": JSON request {"listings": {name: [day, ...], ...}, "start_date": int, "end_date": int}. OJ "Hotel Split Stay": n (integer, number of hotels, 2 <= n <= 100); hotels: a 2D list where hotels[i] is the list of available dates ("YYYY-MM-DD" strings) for the i-th hotel; start_date / end_date as "YYYY-MM-DD" strings.
Output
Curated / "Find Split Stays": all unordered pairs of listing names that can form a valid split stay (return order unspecified; whether a degenerate single-listing coverage counts should be clarified with the interviewer). OJ "Hotel Split Stay": whether the request can be completely covered by two different hotels, and all possible hotel-index-pair combinations, e.g. [(0, 1), (0, 2)].
Examples
Example 1
Input
listings = {"A": [1,2,3,6,7,10,11], "B": [3,4,5,6,8,9,10,13], "C": [7,8,9,10,11]}, dateRange = [3, 11]
Output
[("B", "C")]
Explanation
B covers 3-6, C covers 7-11. Reused verbatim (same listings, same range) by the OJ page "Find Split Stays for Airbnb Listings", whose input is {"listings": {"A": [1,2,3,6,7,10,11], "B": [3,4,5,6,8,9,10,13], "C": [7,8,9,10,11]}, "start_date": 3, "end_date": 11}.
Example 2
Input
3 [["2023-01-01", "2023-01-02", "2023-01-03"], ["2023-01-02", "2023-01-03", "2023-01-04"], ["2023-01-04", "2023-01-05"]] "2023-01-01" "2023-01-05"
Output
[(0, 1), (0, 2)]
Explanation
OJ "Hotel Split Stay" sample test: 3 hotels with per-hotel available dates, requested range 2023-01-01..2023-01-05.
Follow-ups
Bonus credit for a bitmask solution where each listing's availability over the requested window becomes an N-bit mask; the answer is every pair whose OR equals the full-window mask and whose split point exists.
Asked to extend to 3-listing splits or to maximize the number of distinct listings used.
Asked for the API contract (request / response schema, pagination if the listing set is large).
Loading the solution…
