Failed to Form Biggest Number

I failed 5 test cases. So, can anyone give some test cases or check my code?

Hello @Kinjal,

Your code will fail for cases like:
1
2
98 9899
Expected Output:
989998
Your Output:
989899
Reason:
In the if-else conditions, you have nested if condition that is comparing only one character only.
After iterating 9, 8 of both the numbers.
The while loop will terminate and as temp_==strlen(A[j]):
it will not satisfy the nested if condition and swapping will not occur.

Hope, this would help.
Give a like if you are satisfied.

Yes, thanks for that test case but still 5 cases failed. Can you look up?

Can anyone look up my code? I still failed 5 test cases.

Hey @S18ML0016,

Including equality in the conditional check would not solve the problem.
Example:
1
2
58 5851
Expected Output:
585851

NOTE:
just comparing the first element would not solve the problem.

I am just gave up with my logic.

Hey @Kinjal,

Your logic is not incorrect.
It’s just you have missed the case that i have specified in my previous replies.

The following code has made comparison much simpler:

Let me know if you don’t understand something.
Hope, this would help.
Give a like if you are satisfied.

Thank you. Your code is so simple tho you have used sort function. But I just didnt want to use sort instead of this, i used bubble sort which makes lots of comparison and I dont know which case I have left to include. So, I gave up.

@Kinjal,

No, you can apply the same logic: concatenating 2 strings
and then comparing them inside a for loop also instead of using the sort function directly.

I know you were applying bubble sort.
The only case that you have missed is to compare all digits of a number.
In the example:
2
98 9899
once you have iterated for the first two digits i.e. 9 and 8 of both the numbers,
you should compare the next digit of the second number(in this case) with the first of the first digit.
i.e. 9 is equal 9
Now, moving to the next position.
Comparing 8 with 9: 8<9 so swap them.

Similarly, in the example:
1
2
58 5851
Comparing 8 and 1: 8>1 so do not swap.

Hope, this would help.
If you want, I can correct your code.

Don’t leave it so easily.
Some questions/logics do need time.
So, it’s okay.

1 Like

I am very grateful that you told me where I fucked up or what I left to include in my code. Okay, I will do that and then will talk again, brother.

What about the case like: 58 58581. What will be the condition for that kinda cases?


Can you look up?
P.S. tho it’s not executing in the online coding blocks ide but it will run in offline ide. like devc++

@Kinjal for this case, swapping will not occur.


can you run it, tell me if i have left any test cases?