← Questions

Group booking across properties in one neighborhood

0
AirbnbCodingLast asked May 2026

A rental company houses groups in its properties. A group may be split across several properties, but all of them must be in the neighborhood the group asked for.

Implement BookingSystem:

  • BookingSystem(properties): properties is a list of [id, neighborhood, capacity] (all strings; capacity is a positive integer). All properties start free.
  • book(neighborhood, group_size) -> list[str]: choose free properties in neighborhood for the group, mark them booked, and return their ids sorted. Return [] (and book nothing) if no choice fits.

Choose the set using these rules, in order:

  1. The total capacity is at least group_size.
  2. Use the fewest properties.
  3. Among those, use the smallest total capacity (fewest empty beds).
  4. If there is still a tie, return the lexicographically smallest sorted list of ids.

Constraints: up to 100 properties per neighborhood, capacity and group size up to 1,000.

Example 1

properties = [["a","soma","4"], ["b","soma","3"], ["c","soma","5"], ["d","soma","2"], ["e","mission","6"]]
book("soma", 7)    -> ["a", "b"]   # two properties, total 7; ties with ["c","d"], wins on ids
book("soma", 7)    -> ["c", "d"]   # a and b are booked now
book("soma", 1)    -> []           # nothing free left in soma
book("mission", 6) -> ["e"]

Example 2

properties = [["p","h","10"], ["q","h","5"], ["r","h","5"]]
book("h", 4) -> ["q"]   # one property either way; 5 wastes fewer beds than 10
Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding