Question d’entretien chez Amazon

A challenging dynamic programming question.