Getting TLE in this question

Hello …
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…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Hey @ashishnnnnn
Top down solution can’t be optimized further.

Now regarding Bottom Up approach
First read this https://www.geeksforgeeks.org/constant-time-range-add-operation-array/
Then go through the editorial code and if u don’t understand then let me know.

This code is same as that in the editorial just written in more complex manner

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.