Both code produce same output yet one of them fails after submitting

i wrote a code that failed all cases after submitting (it passed only testcase no 4),so i rewrote a logic with different approach that passed all cases now after unlocking testcases i found that both code give same output yet one fails for some reason i dont know i have provided one of testcase for sample(that was showing wrong ouput for one code but second code passed)

passing all test cases code:https://ide.codingblocks.com/s/214045

failing code:https://ide.codingblocks.com/s/214051

please help me find issue

hey @himanshu0ayush there is very subtle mistake in the logic of the first one, if given 2 string you have to return a +b > b + a. which you are doing in second case but in the first case you are lexicographically comparing string a and b but if one string is pre fix of another you return the one with bigger length which is wrong. and since the whole pre fix needs to be same in order to trigger the mistake it is only triggered when the test cases are big enough hence only one case passed.

for examle in simple case of
1
2
5 52
the code which is failing all the test cases return 525 when the correct solution is 552

oh yah right that was the case i forgot for failing case and an important point…but i dont think that was case for prefix in the testcase provided by me in link of passing code(commented at bottom) that tecase was one of the failing testcase i wonder why it was failing…

after dry running i got to know my failing code runs both cases:
1
2
5 52
op:552
1
2
5 57
op:575
i still dont know why its failing(it is working for prefix case becausewhile loop will go on until max length reaches 0,as the l_char string index_pointer stops increasing due to if condition)

the problem is in the process of comparing only as this code passes all the test cases: