A pricing page offers add-ons with prices in prices. A customer can pick any set of add-ons, including none, and each add-on at most once.
Write countAffordableBundles(prices, budget) that returns how many sets of add-ons have a total price of at most budget.
Add-ons with equal prices are still different add-ons, so picking one or the other counts as two different sets.
Input: prices = [3,5,9], budget = 10 Output: 5
The sets {}, {3}, {5}, {9}, and {3, 5} cost 10 or less. {3, 9} costs 12.
Input: prices = [4,4], budget = 8 Output: 4
None, either 4 alone, or both: all cost 8 or less.
0 <= prices.length <= 150 <= prices[i] <= 10000 <= budget <= 15000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #294 Bundles Within Budget. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.