Morgan Stanley interview question

leetcode question, don't remember eactly, but it is an easy dp