Every cheapest way to order from a combo menu
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 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_totalis the lowest total price of any combination, as a string with two decimals. UseNoneif no combination exists. -
combinationslists every combination whose total equalsmin_total. Sort the IDs inside each combination, and sort the list of combinations. Return[]if none exists. - An empty
userWantscosts"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
ientries. With 15 wanted items that is2^15masks, 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
mcheapest 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
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.
