FactSet interview question

Question about DP, something similar to leetcode