Question d’entretien chez Amazon

1 dynamic programming question, another medium question