Pergunta de entrevista da empresa JPMorganChase

A somewhat common dynamic programming problem.