Amazon Interview Question

leetcode hard question using dynamic programming