Bloomberg Interview Question

DP or Graph solution question.