My solution is giving WA - https://hack.codingblocks.com/submission/2300871
Need Help…
Problem in FORM BIGGEST NUMBER questio
@saurabhpandey59373 hey saurabh share the link of you code after saving on cb.lk/ide.it will generate a url that url you have to share.
@saurabhpandey59373 hey saurabh your compare function is right try this compare function
int myCompare(string X, string Y)
{
// first append Y at the end of X
// then append X at the end of Y
// Now see which of the two formed numbers is greater
return XY.compare(YX) > 0 ? 1: 0;
}
@saurabhpandey59373 hey saurabh
A simple solution that comes to our mind is to sort all numbers in descending order, but simply sorting doesn’t work. For example, 548 is greater than 60, but in output 60 comes before 548. As a second example, 98 is greater than 9, but 9 comes before 98 in output.
So how do we go about it? The idea is to use any comparison based sorting algorithm. In the used sorting algorithm, instead of using the default comparison, write a comparison function myCompare() and use it to sort numbers. Given two numbers X and Y, how should myCompare() decide which number to put first – we compare two numbers XY (Y appended at the end of X) and YX (X appended at the end of Y). If XY is larger, then X should come before Y in output, else Y should come before. For example, let X and Y be 542 and 60. To compare X and Y, we compare 54260 and 60542. Since 60542 is greater than 54260, we put Y first.