Group booking across properties in one neighborhood
I was asked this
No reports yet. Sign in to say where you were asked it.
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):propertiesis a list of[id, neighborhood, capacity](all strings;capacityis a positive integer). All properties start free. -
book(neighborhood, group_size) -> list[str]: choose free properties inneighborhoodfor 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:
- The total capacity is at least
group_size. - Use the fewest properties.
- Among those, use the smallest total capacity (fewest empty beds).
- 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
capacitya 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 atgroup_size + max capacityfinds both, about100 * 100 * 2000steps 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
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
