Domanda di colloquio di PayPal

An algorithm question related to dynamic programming. I am asked to write pseudo/real code by hand to solve that problem.