Loading
Loading
A procurement team has a list of item costs and a budget. Each item may be taken at most once.
Return how many distinct selections of items sum to exactly the budget. Two selections differ if they use different positions, even when the costs are equal. The empty selection counts when the budget is zero.
costs = [2, 3, 5], budget = 5{2, 3}sums to 5{5}sums to 52Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(2ⁿ) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
{2,3} and {5}.
Example 2
The two 1s are at different positions, so they are different selections.
Example 3
The empty selection.