Skip to the code
cf.
+10 XP

#294 Bundles Within Budget

easy

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.

Example 1

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.

Example 2

Input: prices = [4,4], budget = 8
Output: 4

None, either 4 alone, or both: all cost 8 or less.

Constraints

  • 0 <= prices.length <= 15
  • 0 <= prices[i] <= 1000
  • 0 <= budget <= 15000
Saved in this browser

Run 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).