← Questions

Every cheapest way to order from a combo menu

0
AirbnbCodingLast asked May 2026

A coding interview question asked in Airbnb's coding round, last asked May 2026. It tests bitmask dp, backtracking and set cover.

A food ordering app wants to show a customer every cheapest way to buy the dishes they want.

The menu is a list of entries. Each entry is (id, price, items):

  • id: a unique positive integer.
  • price: a positive decimal string with at most two decimal places, such as "7.25".
  • items: a comma-separated list of distinct item names, such as "burger" or "burger,shake,fries". An entry with more than one item is a combo.

The customer gives userWants, a list of distinct item names.

Implement cheapest_orders(menu, userWants) -> (min_total, combinations).

A combination is a set of entry IDs, each used at most once, whose items together include every name in userWants. Items the customer did not ask for may be included, and two entries may share an item.

  • min_total is the lowest total price of any combination, as a string with two decimals. Use None if no combination exists.
  • combinations lists every combination whose total equals min_total. Sort the IDs inside each combination, and sort the list of combinations. Return [] if none exists.
  • An empty userWants costs "0.00" with one empty combination.

Constraints

  • Up to 15 distinct wanted items.
  • Up to 100 menu entries, each with up to 15 items.
  • Compare prices exactly (do not let floating-point error decide ties).

Example 1

menu = [(1, "6.00", "taco"), (2, "5.00", "salad"), (3, "9.00", "taco,salad"),
        (4, "4.00", "soda"), (5, "13.00", "taco,salad,soda")]
userWants = ["taco", "salad", "soda"]

-> ("13.00", [[3, 4], [5]])

Buying 1, 2 and 4 costs 15.00. Entry 3 plus entry 4 and entry 5 alone both cost 13.00.

Example 2

menu = [(1, "2.00", "a"), (2, "2.00", "b"), (3, "4.00", "a,b"), (4, "4.00", "a,b,c")]
userWants = ["a", "b"]

-> ("4.00", [[1, 2], [3], [4]])

Entry 4 counts even though it includes c, which was not asked for.

Part I of this question usually asks only for the minimum total. Follow-ups may add item quantities, an exact-match rule, or a limit on how many combinations to return.

Clarifying questions

  • Can two combinations with the same IDs appear twice? (No: each combination is a set.)
  • Are menu items and wanted items compared exactly, including case?
  • Can the number of cheapest combinations be very large, and should it be capped?
  • Is a price like "7.5" (one decimal place) valid?

What a strong answer covers

  • Converts every price to integer cents, so ties are exact.
  • Turns each entry's items into a bitmask over the wanted items, and ignores entries that cover none of them (with positive prices they can never be in a cheapest set).
  • Runs a 0/1 DP over the entries and the covered mask: the cheapest cost to reach each mask using the first i entries. With 15 wanted items that is 2^15 masks, so O(entries x 2^15).
  • Rebuilds every cheapest set by walking the DP back from the full mask, branching wherever skipping or taking an entry both give the best cost. Each branch is a different set, so there are no duplicates.
  • Formats the total with two decimals and sorts the IDs and the combinations.
  • Tests both examples, an empty userWants, an item no entry has, and two entries with the same items and price.

Follow-ups

  • The customer wants quantities, such as two tacos.
  • The combination must contain exactly the wanted items and nothing else.
  • Return at most m cheapest combinations.
  • Menus with hundreds of wanted items: what breaks, and what would you do instead?

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

bitmask dp · backtracking · set cover

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