Pregunta de entrevista de Amazon

Leetcode medium one-dimensional dynamic programming question.