Domanda di colloquio di Citadel Securities

asked to solve a problem about dynamic programming