Roblox interview question

Leetcode medium -hard . Dynamic programming