Menu Minimum Cost

Asked at AirbnbOnsite

Reported by the problem's creator, not verified

A menu sells bundles. Each bundle is a list of foods with one price, and you may buy any bundle any number of times. You want to end up with every food in a wanted list, and a bundle may hold extra foods you do not want; those are simply ignored.

Write cheapest_cover(bundles, prices, wanted), where bundles[i] lists the foods in bundle i and prices[i] is its price. Return [cost, chosen]: the lowest total price that gets every wanted food, and the indices of the bundles to buy, in increasing order. Each chosen bundle appears once.

Examples

  1. Example 1

    Input: bundles = [["a","b","c"],["d","e"],["a","c"]], prices = [5,2,1], wanted = ["a","c","d"]

    Output: [3,[1,2]]

    Explanation: Bundle 0 is not needed: bundle 2 (a, c) costs 1 and bundle 1 (d, e) costs 2. The extra e is ignored. The cost is 3 and the bundles are 1 and 2.

  2. Example 2

    Input: bundles = [["burger"],["fries"],["burger","wings"]], prices = [50,30,70], wanted = ["wings","fries"]

    Output: [100,[1,2]]

    Explanation: wings is only in bundle 2, which also holds burger; that is fine, the extra food is ignored. With fries (30) the cost is 100.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.