Pregunta de entrevista de Cisco

There was a programming question which we have to solve using dynamic programming