Amazon interview question

Leetcode medium one-dimensional dynamic programming question.