Fractal interview question

LC Dynamic Programming Medium level question