Morgan Stanley Interview Question

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