JPMorganChase Interview Question

A somewhat common dynamic programming problem.