Choose Properties for a Group

Asked at AirbnbPhone screen

Reported by the problem's creator, not verified

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).

Examples

  1. Example 1

    Input: {"properties":[[1,"N1",2],[2,"N1",3],[3,"N1",4],[4,"N2",10]],"neighborhood":"N1","group_size":7}

    Output: [2,3]

    Explanation: 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.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.