Covalense Global interview question

Coding question regarding dp in python