Form the biggest number

You are provided an array of numbers. You need to arrange them in a way that yields the largest value.

can i get hints for this que

Hey Ankush, for this problem you can treat the array’s elements as strings and sort them in lexicographically decreasing order. For eg. [54, 546, 548, 60] if you sort these in lexicographically decreasing order result will be [60, 548, 546, 54] , then you can print all the elements and it will form the biggest number.

ans is correct but #test case say wrong answer https://ide.codingblocks.com/s/53492

Hey Ankush, your output should exactly match the given output format of the problem, so print the output for each test case in a new line.

still showing incorrect

https://ide.codingblocks.com/s/53701

Hey Ankush, your code is not handling some of the cases, for eg.
input:
1
8
1 34 3 98 9 76 45 4

your code’s output:
989764543431

but the expected output is:
998764543431

i have tried but not get the logic di… can yu pls provide hints for that

Hi Ankush, let us suppose you have to arrange two numbers A and B to obtain the larger number. You will have to decide which number to put first – we compare two numbers AB ( B appended at the end of A) and BA (A appended at the end of B). If AB is larger, then A should come before B in output, else B should come before. You can append them as strings for comparison.

1 Like

Hey Ankush, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.

i dont think what you are saying is correct

why can’t we just sort lexicographically

consider the case 123 1231
when you compare them lexigraphically then you get the order
1231123
but the order should be
1231231
you can test that
dont expect just changing the comparison sign will solve your problem