Pergunta de entrevista da empresa IBM

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