Amazon Interview Question

1 dynamic programming question, another medium question