Pregunta de entrevista de Amazon

I was asked question on dynamic programing