Citadel Securities Interview Question

asked to solve a problem about dynamic programming