Pergunta de entrevista da empresa IBM

Dynamic programming related coding question.