"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"# Challenge Notebook"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Problem: Given a knapsack with a total weight capacity and a list of items with weight w(i) and value v(i), determine the max total value you can carry.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Constraints\n",
"\n",
"* Can we replace the items once they are placed in the knapsack?\n",
" * Yes, this is the unbounded knapsack problem\n",
"* Can we split an item?\n",
" * No\n",
"* Can we get an input item with weight of 0 or value of 0?\n",
" * No\n",
"* Do we need to return the items that make up the max total value?\n",
" * No, just the total value\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* Are the inputs in sorted order by val/weight?\n",
" * Yes\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Test Cases\n",
"\n",
"* items or total weight is None -> Exception\n",
"* items or total weight is 0 -> 0\n",
"* General case\n",
"\n",
"<pre>\n",
"total_weight = 8\n",
"items\n",
" v | w\n",
" 0 | 0\n",
"a 1 | 1\n",
"b 3 | 2\n",
"c 7 | 4\n",
"\n",
"max value = 14 \n",
"</pre>"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."