Maximizing value of your knapsack


Consider a backpack (or "knapsack") that can hold up to a specified amount of weight. You have a set of items each having a unique value and unique weight.

Given this information, write an algorithm that fills the backpack with the most valuable items within the backpack's capacity. Below is an example:

# Input:
values = [3, 5, 6] 
weight = [1, 2, 3] 
backpack_capacity = 5

# Output: 
# Here the capacity is 5, so we'll take items with values 6 and 5, 
# taking our total weight to capacity while maximizing value

The function should be able to take in the above variables: values, weight, and backpack_capacity, returning the maximum value of the backpack.


Access restricted

Subscribe to premium account to see the solution.

Get premium now