I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 0-1 knapsack problem | |
For an overall introduction to knapsack problem, see https://en.wikipedia.org/wiki/Knapsack_problem | |
Function name: knapsack | |
Param: | |
items: an array of {w: v:} (where 'w' stands for weight, and 'v' stands for value) | |
capacity: a positive integer number | |
Will return max sum value that can reach, and the chosen subset to add up to the value. |