← Questions

Group booking across properties in one neighborhood

0
AirbnbCodingLast asked May 2026

A coding interview question asked in Airbnb's coding round, last asked May 2026. It tests dynamic programming, knapsack and design.

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

Clarifying questions

  • Is capacity a positive integer stored as a string, and should it be parsed once at construction?
  • Is a group of size 0 possible, and what should it return?
  • Are ids compared as strings for the lexicographic tie-break, on the sorted list of ids?
  • Can bookings be cancelled, freeing properties again?

What a strong answer covers

  • Groups free properties by neighborhood at construction.
  • Treats the choice as a knapsack over two dimensions: the fewest properties first, then the smallest total capacity at least group_size. A DP over (number used, total capacity) capped at group_size + max capacity finds both, about 100 * 100 * 2000 steps per booking.
  • Gets the lexicographic tie-break by deciding the ids in sorted order, keeping a property only when the rest can still reach the chosen count and capacity (a suffix DP answers that).
  • Notes that greedy largest-first finds the fewest properties but not the fewest empty beds, with a counterexample.
  • Tests both examples, a group larger than the whole neighborhood, and an unknown neighborhood.

Follow-ups

  • Add cancel(ids).
  • Bookings have dates, so a property is free only on some nights.
  • Larger neighborhoods (thousands of properties): what changes?

Where it's asked

  • Airbnb · Coding · Last asked May 202645 min · Live coding, one or two rounds, from the same pool as the screen

What it tests

dynamic programming · knapsack · design

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding