Getting TLE in this question

Hii…
I am doing this question from hackerearth…

This is my solution based on memoization approch…
https://www.hackerearth.com/submission/51251364/

Please recommend me what changes should i do … so it passes all test cases…

There is one more approach like…
Iterate from the back of the array and calculate ans…
Like this submission of one guy…
https://www.hackerearth.com/submission/51105268/
If possible please explain this…

Thanks…

Hello @ashishnnnnn your doubt is not showing in my section so you can raise your doubt again someone will help you.
Happy Learning!!