My code is getting TLE...although I used 3D memoization in it

In the question it was said that this question will be done by 4D dp…I used 3D dp in it and I am getting TLE in this…although the 4th column on the video has on 2 as it’s size…I don’t know why I am getting TLE… https://ide.geeksforgeeks.org/A1ttpeYSvr this is the solution URL please help…

Hey @kaushikjatin
Your loop 63-70 is causing the TLE
This is my solution
You can just consider the last elements and no need to consider elements in the middle till they are equal
https://codeforces.com/contest/682/submission/70835957
You can see my solution here and compare

If your doubt is resolved please close it

@Aarnav-Jindal-1059677350830863 thanks bro for the solution but I already figured it out. And by the way bro can u please help in some of my other doubts.I have a doubt in Money change question in that I used memoization but I am getting TLE .I know I can optimize the space but ther error coming is TLE I don’t know how.I have again raised the doubt in that.

1 Like