Concentric AI interview question

DP problem for the DSA round