Algorithms Playbook
← All problems
MediumKnapsack →Similar to: 0/1 Knapsack

Best loot for the bag

Problem

Given weights[i] and values[i] for n items and a bag capacity, return the maximum total value you can carry. Each item can be taken at most once.

Examples

Input: weights = [2,3,4], values = [3,4,5], capacity = 5

Output: 7

Take the items of weight 2 and 3.

Input: weights = [5], values = [10], capacity = 4

Output: 0

Hints

    Try it first. Every hint reveals a bit more.

    Solution