A9.com Interview Question

I misunderstood a question on Dyanamic Programming but figured it out later on.