Find minimal property set in neighborhood
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates combinatorial optimization and algorithm design skills, focusing on capacity-constrained selection (subset-sum/knapsack-style reasoning), deterministic tie-breaking, and complexity analysis within the Coding & Algorithms domain.
Constraints
- 0 <= len(properties) <= 200
- Each property is a tuple (id, neighborhood, capacity)
- IDs are unique integers; duplicate capacities are allowed
- 1 <= capacity <= 1000
- 0 <= groupSize <= 20000
- The sum of capacities of properties in targetNeighborhood is at most 20000
Examples
Input: ([(1, "downtown", 5), (2, "downtown", 3), (3, "downtown", 1), (4, "uptown", 4), (5, "uptown", 2)], "downtown", 6)
Expected Output: [1, 3]
Explanation: No single downtown property reaches 6. Both [1, 2] and [1, 3] use 2 properties, but [1, 3] has smaller total capacity: 6 instead of 8.
Input: ([(1, "downtown", 5), (2, "downtown", 3), (3, "downtown", 1), (4, "uptown", 4), (5, "uptown", 2)], "downtown", 3)
Expected Output: [2]
Explanation: Property 2 alone reaches the target, so 1 property is optimal.
Hints
- This is a 0/1 knapsack or subset-sum variant: exact sums matter because two solutions with the same number of properties can overshoot by different amounts.
- After you know the optimal count and exact total capacity, sort the matching properties by ID and reconstruct greedily to get the lexicographically smallest valid ID list.