Pregunta de entrevista de Amazon

Dynamic Programming kind of question