IBM interview question

Leetcode medium-hard question, one of them was a knapsack problem.