Split Stay
AirbnbPhone screenMedium
A guest wants to stay from day start through day end, both included, but no single listing is free for the whole trip. A split stay books two different listings back to back: the first covers days start through some split day s, the second covers days s + 1 through end. Each listing reports the days it is free, in any order and possibly with repeats.
Part 1: Find the two-listing stays
Given availability, where availability[i] is the list of free days of listing i, return every ordered pair [x, y] of different listings for which some split day s with start <= s < end exists such that listing x is free on every day from start to s and listing y is free on every day from s + 1 to end.
A pair appears once in the result even if several split days work for it. Sort the pairs by x, then by y.
- Example 1
- end
5- start
1- availability
[[1,2,3],[3,4,5],[5,4,3,2,1],[2,3,4,5]]- Output
[[0,1],[0,2],[0,3],[2,1],[2,3]]
Why: Only listings free on day 1 can come first: 0 and 2. With 0 first, listing 1 covers days 4-5, so [0, 1] works; [0, 2] and [0, 3] also work since both are free on days 2-5. With 2 first, [2, 1] splits after day 2 and [2, 3] splits after day 1. [2, 0] fails because 0 is not free on day 5.
Constraints
1 <= len(availability) <= 2000 <= len(availability[i]) <= 10000 <= availability[i][j] <= 10^90 <= start < end <= 10^6