Form_biggest_number

can anyone help me find where i am going wrong

Hey @swatiguptasg
Your code would show wrong results for certain cases, Consider the following case:
8
1 34 3 98 9 76 45 4

Your code would show the result:
989764543341
while the correct answer should be:
998764543431

so the problem is where you compare the strings,
your code doesn’t handle this case, for such strings where till a particular point, both are equal and then one string terminates,
eg let string A = β€œ98”
string B = β€œ9”
for comparison/swapping,
string AB = A.append(B) // 989 in this case
string BA = B.append(A) // 998 in this case
You need to check which of AB and BA is greater and then figure out whether or not swapping is needed.

1 Like