Domanda di colloquio di Amazon

Question related to Dynamic Programming which was HARD difficulty