Pregunta de entrevista de Roblox

Leetcode hard question involving DP