Getting the wrong answer

can you please tell if there is a better approach and how should i correct and improve this code

You can use top down dp approach.