Bloomberg interview question

DP or Graph solution question.