Hey, Guys, I watched Video From Aditya Verma series and then Write Optimise Code for
Palindromic String Partition but it is giving me TLE.
Please check it
Actually I don’t understood the bottom up dp for this problem i,e., I decided to solve using top down approach.
I also unable to figure out why its giving me TLE.
Argh. I see why. Pass your string by reference and not by value. If you pass it by value, the string is copied for each and every call, which is another \mathcal O(n). So the overall runtime is \mathcal O(n^3).
Don’t memset all 1500*1500 values for every test case. That’s because sum of n over all test cases might be lesser than than T*1500*1500. I tried changing it but it still give TLE.
@ssjgz, are there any flaws with a top down dp, which increases the runtime? Feels like a state will be accessed 2^n times. But I haven’t really faced/seen problems where that causes an increased runtime.