Calvins's game runtime error


please tell me whats wrong with my code why it is giving me runtime error ?? i have done dry run of it also still unable to find the mistake

Hey @Shobhit_kumar
I corrected your code and mentioned the changes in comments : https://ide.codingblocks.com/s/350741
Its working fine on random small test case(tried till 1000) ,But not working on large testcases(as that of input file) because of recursion overhead which is resulting in runtime error .

Try to solve it by bottom up approach.

kartik sir so recursion stack overloading also causes runtime error ??

yup recursion overhead may lead to excess memory usage which isn’t available giving runtime error

@Kartik Khariwal sir why have u added if(k==1&&forward==false) return 0;//correction as base case and not this -> if(k==1) return 0 because it if the person is in index 1 then he is in his destination so why will he go further anywhere?? what if his starting point itself is 1??

say we have
2 1
5 6
so i will go to 6 and then come back to 5 to maximize my profit

Hey @Shobhit_kumar
If u dont have any other doubt in this then please mark it as resolved :slight_smile:

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.