Find a split-stay booking across listings
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates understanding of interval coverage and algorithmic problem solving, specifically reasoning about continuous date ranges, split-interval feasibility, and efficient handling of multiple sorted availability intervals.
Constraints
- 1 <= len(avail) <= 2 * 10^5
- The total number of intervals across all listings is at most 2 * 10^5
- Intervals inside each listing are sorted by start and do not overlap
- Dates fit in 32-bit signed integers
- start < end
- For the split-stay case, A and B must be different listing IDs
Examples
Input: ([[(1,10)],[(1,4),(5,9)]], 2, 7)
Expected Output: (True, (0,))
Explanation: Listing 0 is available for the full interval [2,7), so a single-listing stay works.
Input: ([[(1,4)],[(4,8)],[(2,3),(3,5)]], 1, 8)
Expected Output: (True, (0, 1, 4))
Explanation: Listing 0 covers [1,4) and listing 1 covers [4,8), so switching on day 4 gives continuous coverage.
Input: ([[(1,3),(3,6)],[(6,8)]], 2, 6)
Expected Output: (True, (0,))
Explanation: The two intervals of listing 0 touch, so together they form continuous availability [1,6), which covers the whole trip.
Input: ([[(1,3)],[(4,6)],[(6,7)]], 1, 7)
Expected Output: (False, None)
Explanation: No single listing covers [1,7), and no pair of distinct listings can cover it without a gap.
Input: ([[(-5,-2)],[(-2,1)],[(-10,-6)]], -5, 1)
Expected Output: (True, (0, 1, -2))
Explanation: Listing 0 covers [-5,-2) and listing 1 covers [-2,1), so a valid split exists with switch day -2.
Input: ([[],[(0,2)],[(2,4)]], 0, 4)
Expected Output: (True, (1, 2, 2))
Explanation: Listing 1 covers [0,2) and listing 2 covers [2,4). The empty listing does not affect the answer.
Hints
- First merge touching intervals within each listing into maximal continuous blocks.
- For each listing, you only need to know two things: how far right it can continuously cover starting from start, and how far left it can continuously cover ending at end.