Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Monday, Dec 7.Claim the deal

A food delivery service wants to help customers minimize the total cost of ordering a specific set of dishes from a restaurant menu.

  • The menu is provided as a list of entries, where each entry consists of a unique ID, a price, and a comma-separated list of unique item names (representing either a single item or a combo meal), in the format "<item1>,<item2>,...".
  • The customer specifies their order as userWants, a list of unique item names they wish to obtain.

Your task is to find all unique combinations of menu entry IDs such that:

  • The selected menu entries together provide all items in userWants.
  • The total cost of the selected entries is minimized.
  • Any extra items included in the selected combos that are not part of userWants can be ignored.

Return a list of all unique combinations of menu entry IDs (in any order within each combination) that achieve the minimum total cost and cover all items in userWants. If it is impossible to fulfill the order, return an empty list.

Note: Each combination must be returned as a list of IDs. The order of IDs within a combination is unimportant, and the combinations themselves may be returned in any order. For floating-point comparisons, consider two total costs equal if their difference is within an epsilon of 1e-6.

Constraints:

  • 1 ≤ menu.length ≤ 100
  • 1 ≤ userWants.length ≤ 20
  • Each menu entry contains at least one item.
  • Every item in each menu entry is unique.
  • Every item in userWants is unique.

Example 1:

Input: menu = [["1", "5.00", "pizza"],         ["2", "8.00", "sandwich,coke"],         ["3", "4.00", "pasta"],         ["4", "2.00", "coke"],         ["5", "6.00", "pasta,coke,pizza"],         ["6", "8.00", "burger,coke,pizza"],         ["7", "5.00", "sandwich"]], useWants = ["sandwich", "pasta", "coke"]

Output: [["3", "4", "7"], ["5", "7"]]

Explanation: One optimal way is to select menu entries with IDs "3" (pasta), "4" (coke), and "7" (sandwich), which totals 11.00. Alternatively, you can choose "5" (pasta, coke, pizza) and "7" (sandwich), also totaling 11.00. Both options achieve the minimum possible total cost.

Example 2

Input: menu = [["1", "5.00", "pizza"],         ["2", "8.00", "sandwich,coke"],         ["3", "4.00", "pasta"],         ["4", "2.00", "coke"],         ["5", "6.00", "pasta,coke,pizza"],         ["6", "8.00", "burger,coke,pizza"],         ["7", "5.00", "sandwich"]], userWants = ["burger", "pasta"]

Output: [["3", "6"]]

Example 3

Input: menu = [["1", "5.00", "specialItem"],         ["2", "10.00", "specialItem,extra1"],         ["3", "8.00", "specialItem,extra2"],         ["4", "15.00", "specialItem,extra1,extra2"]], userWants = ["specialItem", "nonExistingItem"]

Output: []


Accepted
2.7k/7.6k
Acceptance Rate35.5%
Test Cases
Input
menu =
userWants =
Output
Expected