Canva interview question

Dynamic programming problem with optimization