Choose Properties for a Group
AirbnbPhone screenMedium
A booking system lists properties as [id, neighborhood, capacity]: a unique integer id, the neighborhood the property is in, and the number of guests it holds. A group of guests must stay in one neighborhood, spread over as many of its properties as needed.
Write choose_properties(properties, neighborhood, group_size).
Part 1: Smallest fitting set
A set of properties fits the group when their capacities add up to at least group_size. Return the ids of the best fitting set among the properties in neighborhood, where the best set has the smallest total capacity. If several sets share that total, the best has the fewest properties. If several still tie, the best is the one whose ids, sorted ascending, come first when compared element by element (so [1, 4] comes before [2, 3], and [2] before [2, 3]).
Return the ids in ascending order, or an empty list when no set fits, even using every property in the neighborhood.
Different properties may have the same capacity. Properties in other neighborhoods are never used.
- Example 1
- properties
[[1,"N1",2],[2,"N1",3],[3,"N1",4],[4,"N2",10]]- neighborhood
"N1"- group_size
7- Output
[2,3]
Why: Only properties 1, 2 and 3 are in
N1. Properties 2 and 3 hold 3 + 4 = 7, exactly the group size, and no subset reaches 7 or more with a smaller total. Property 4 is in another neighborhood and is ignored.
Constraints
1 <= len(properties) <= 601 <= properties[i][0] <= 10^6, and every id is distinct1 <= properties[i][2] <= 10001 <= group_size <= 10^41 <= len(neighborhood) <= 20