Compute minimum-cost service cover
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in combinatorial optimization and set-coverage with cost minimization, including handling case-insensitive service matching and enumerating minimal solution combinations.
Constraints
- 0 <= N <= 30, where N is the number of packages
- 0 <= price <= 10^6 for each package
- 0 <= S <= 15, where S is the number of distinct required services after case-insensitive normalization
- The number of optimal combinations can be exponential in N, so reconstruction is inherently output-sensitive
Examples
Input: ([(["wifi"], 50), (["parking"], 30), (["parking", "tv"], 70)], ["WiFi", "parking"])
Expected Output: (80, [[0, 1]])
Explanation: Package 0 covers wifi and package 1 covers parking for a total of 80. Package 2 does not include wifi, so using it with package 0 costs 120 and is not optimal.
Input: ([(["wifi"], 50), (["tv"], 20)], ["wifi", "parking"])
Expected Output: (-1, [])
Explanation: No package provides parking, so it is impossible to cover all required services.
Input: ([(["a"], 5), (["b"], 5), (["a", "b"], 10)], ["A", "B"])
Expected Output: (10, [[0, 1], [2]])
Explanation: Either buy packages 0 and 1 for 10 total, or package 2 alone for 10. Both are optimal.
Input: ([(["wifi"], 50)], [])
Expected Output: (0, [[]])
Explanation: No services are required, so the minimum cost is 0 and the empty combination is optimal.
Input: ([(["WiFi", "wifi"], 10), (["PARKING"], 20), (["wifi", "parking"], 40)], ["wifi", "WiFi", "Parking"])
Expected Output: (30, [[0, 1]])
Explanation: Required services normalize to wifi and parking. Package 0 covers wifi for 10, package 1 covers parking for 20, so the best total is 30.
Hints
- Map each distinct required service to a bit position. Then each package becomes a bitmask showing which required services it covers.
- Use DP on (package_index, remaining_services_mask) to compute the minimum cost, then run a DFS that follows only transitions whose cost matches the DP optimum to reconstruct all optimal combos.