Generate split-stay pairs efficiently
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithm design and data-structure competency, focusing on interval reasoning, efficient enumeration of ordered pairs under availability constraints, and time/space complexity analysis for large or sparse date ranges.
Constraints
- 0 <= number of listings <= 2000
- -10^9 <= L <= R <= 10^9
- The total number of availability entries across all listings is at most 2 * 10^5
- Availability lists may be unsorted and may contain duplicates
- Do not assume the range size `R - L + 1` is small enough to scan directly for every pair
Examples
Input: ({'A': [1,2,3,6,7,10,11], 'B': [3,4,5,6,8,9,10,13], 'C': [7,8,9,10,11]}, 3, 11)
Expected Output: [('B', 'C')]
Explanation: B covers days 3 through 6 contiguously, and C covers days 7 through 11 contiguously, so splitting after day 6 works. No other ordered pair covers the full range.
Input: ({'P': [1,2,3], 'Q': [4,5], 'R': [3,4,5]}, 1, 5)
Expected Output: [('P', 'Q'), ('P', 'R')]
Explanation: P can cover the first segment. Q covers 4 to 5, so splitting after 3 gives (P, Q). R covers 3 to 5, so splitting after 2 gives (P, R).
Hints
- For each listing, you do not need to remember every possible split day. It is enough to know how far a contiguous run starting at `L` can extend, and how early a contiguous run ending at `R` can begin.
- When availability is sparse, sort and deduplicate the days, then compress them into consecutive runs. Only the run containing `L` and the run containing `R` matter.