Pergunta de entrevista da empresa Amazon

Question related to Dynamic Programming which was HARD difficulty