Regarding the error

i am getting correct output but testacses are not passing !!!

Hello @gargshivam2001 your code is only running for the sample test case:
for rest all cases your code is not passing the test cases.
for this question basically there are 2 methods :
one by using 2d array and the other by using 1d array but we have to make use of dynamic programming in both the codes.
we can do this by 1d dp by using fibonacci pattern:
Here for your reference i am attaching both the codes.
https://ide.codingblocks.com/s/393731
and second code is this


if you have any doubt you can ask here;
Happy Learning!!

but I have not reached the topic of DP yet !!!
then , why this ques has been given to us ???

Hello @gargshivam2001 this is because so that you can just go with the concept and try to solve this:
but also i have given you the code of fibonaaci this pattern will also work without the applying the dp you can see that.
Ḥappy laearning!!

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.