Amazon interview question

dynamic programming questions from leetcode