Re-wrote it again for the third time since I noticed a few simplifications that I could add and it got accepted!!!
I guess with regards to time limit exceeded,
i added prefix increment operator to my class since that’s all that’s really needed for this (better implementation as well since there’s less digits to go through than before) and at a few places I wasn’t passing string as reference parameters so i made them const reference parameters instead and re-writting stuff probably helped as well since I have a lot less string variable and std:reverse calls now.
I found a number where my class had a wrong answer but I think that’s because I re-wrote it and had a stupid mistake.
9999191291839 <-- input
999919919999 <-- my program was giving this as the next palindrom anwser instead, lol… 1 digit too short
=== Now for the cool part ===
I also found a way that you could better diagnose these wrong answer problems so I figured that I would share, not that I used it for this problem. Used it for a practice one
Looks like if a condition fatally fails say input < output looks you could proably do something like:
if( input.length() < output.length() )
throw length_error("Output length is less than input");
Obviously for something like this you should get rid of leading 0’s from input before comparing. But, instead of getting wrong answer you would get SIGBART which at least you know where in the code that happened. You don’t get told the error but SIGBART is probably easier to figure out than wrong answer. i.e. wrong assumptions etc.