JPMorganChase interview question

A somewhat common dynamic programming problem.