Getting time limit exceeded

Hello…
Wishing You a happy new year…

Here i am trying to solve a graph problem from hackerearth…

I have explained the logic what i have followed pretty well in code with comments…

I have used recursion… I think here we are not recomputiong anything … so i haven’t tried to memoize anything…

This is my submission…
https://www.hackerearth.com/submission/51802113/
Please look at this…
It is showing wrong answer for 1 test case and tle for some.
Thanks.
Happy New Year…:slight_smile:

Hey @ashishnnnnn
Please share ur code in CB IDE

Here it is…

Hey @ashishnnnnn
I don’t think that u have mantained the order of instructions
Correct ?

Can you give an example… Like how my orders are wrong…

I think i got… where i have not followed order… Node where it can move easily as per instruction…
Before it also it can use that extra step…
See this…
It is not showing wrong answer Now…


But it is showing TLE…

But this won’t help u with TLE
Code looks good there might be overlapping subcases when instructions are repeated
So add memoization

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.