Squarepoint Capital interview question

a dynamic programming leetcode problem