https://ide.codingblocks.com/s/230407 please heck, this code is runnning fine for me but all test cases are getting failed?
Form the biggest number problem
@rachitbansal2500
the correct comparator
bool compare(string a,string b){
return a + b > b+a; //return by which you get a bigger number.
}
Hey! I donβt understand why is it so?
think about β909β and β99β
99 < 909 yields true.
but we will put 99 first and then 909 to form the biggest number.
But when we do string comparisons itβs always lexicographical hence a>b will actually yield 909<99
Test case that fails a>b is
1
3
9 990 909
we are not comparing lexicographically. and also to sort lexicographically we can use
bool compare(string a, string b) {
return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()); //return lexo smaller
}
Ok I do understand why lexicographical sort is not the correct option. But we can simply perform lexicographical sort using a>b in string comparisons right?
Yes. we can do that.
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
