how to do the question
Form biggest number int the array
Hi,
So this question seems tough and complex at first
but the main background just using customized sorting
that is can take input as string and
sort the string using customized sorting
ie return a+b > b+a;
for eg:
U Pass in string a as 9 and string b be as 50
so the comparator function compare
a+ b as 950
b+a as 509
return the one larger in value
so 950 will be returned.
This is a string sort question where u have to design a custom comparator
learn about custom comparator
try to code it
in case of any problem msg below i`ll help
can we do without using comparator function
i guess no.
a O( n^2 ) approach
of sorting
please tell the code
why are u not willing to use a comparator class
bool comp(string a , string b) {
return a+b > b+a ;
}
int main(){
int n ;
string str[n];
for(int i = 0 ; i < n ; i++) {
cin >> str[i];
}
sort( str, str+n , cmp) ;
for(int i = 0 ; i < n ; i++)
cout << str[i] <<" ";
}
time complexity O( n log n )
the code is running ,but in submission its coming wrong
bool comp(string a , string b) {
return a+b > b+a ;
}
int main(){
int n ;
string str[n];
for(int i = 0 ; i < n ; i++) {
cin >> str[i];
}
sort( str, str+n , cmp) ;
for(int i = 0 ; i < n ; i++)
cout << str[i] <<"\n"; // back slash character was needed
}