Pregunta de entrevista de Pearson

It was a single technical question. Dynamic programing problem, similar to knapsack problem