Covalense Global Interview Question

Coding question regarding dp in python