Can i have any other alternate and efficient solution for that
My code is not passing all test cases the ( Form biggest number program)
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.
So take input in the form of string. Make your own custom comparator and sort accordingly.
The custom compare function must be something like this:
bool mycompare(string a,string b)
{
string ab=a+b;
string ba=b+a;
return ab>ba;
}
Can you once explain the comparator function
Yes i have figured out the problem but confused
with the working of the mycompare function
Consider the first two elements of the above array:
So in the compare function:
a=54
b=546
ab=54546
ba=54654
Since ba has a larger value than ab, so you have to sort such that b comes before a in the array.
So we return ab>ba (if ab forms the larger number a must come before b in the array and if ba forms the larger number b must come before a in the array)
Ok thank you its cleared