Pergunta de entrevista da empresa Amazon

one hard question from Dynamic programming