MindTickle interview question

Hard level question on Dynamic Programming.