Scaler Academy interview question

Coding Question based on Dynamic programming