Fundamentals/Weight-Only knapsack
← PrevNext →
Prereqs: 0/1 Knapsack
Given a list of weights of n items, find all sums that can be formed using their weights.
Input
weights: A list of n positive integers, representing weights of the items
Output
A list, in any order, of the unique sums that can be obtained by using combinations of the provided weights
Examples
Example 1
Input
weights = [1, 3, 3, 5]
Output: [0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12]
Explanation
We can form all sums from 0 to 12 except 2 and 10. Here is a short explanation for the sums:
Constraints