Menu Minimum Cost
Asked at Airbnb
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
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 extraeis ignored. The cost is 3 and the bundles are 1 and 2.Example 2
Input: bundles =
[["burger"],["fries"],["burger","wings"]], prices =[50,30,70], wanted =["wings","fries"]Output:
[100,[1,2]]Explanation:
wingsis only in bundle 2, which also holdsburger; that is fine, the extra food is ignored. Withfries(30) the cost is 100.