0/1 Knapsack with Weight and Volume Limits
Problem statement
You are given a list of items. Each item is items[i] = [weight, volume, value]. You also get two limits, maxWeight and maxVolume.
Pick any group of items. Each item can be picked at most once. The total weight of the picked items must be at most maxWeight, and their total volume must be at most maxVolume.
Examples
Example 1
items = [[1,2,6],[2,1,5],[2,2,9],[3,3,10]]maxWeight = 4maxVolume = 4return = 15Pick items[0] and items[2]. Their weight is 1 + 2 = 3, their volume is 2 + 2 = 4, and their value is 6 + 9 = 15. Picking items[0] and items[3] would give value 16 with weight 4, but their volume is 5, which is more than 4.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.