Amazon Interview Question

A challenging dynamic programming question.