Pregunta de entrevista de Microsoft

Dynamic programming problem, or maybe it was greedy