Pregunta de entrevista de Silverpush

One question on dynamic programming algorithm was asked.