MyCode:
#include <bits/stdc++.h>
using namespace std;
bool comp(string a,string b){
return a>b;
}
int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
string arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n,comp);
for(int i=0;i<n;i++){
cout<<arr[i];
}
cout<<endl;
}
return 0;
}
Where is wrong?
@ravi.cs18
Hello ravi,
if two numbers are given (let say a and b)
then formed number can be ab or ba
now u need to compare these newly formed number and should consider that which is forming big integer.
so in ur comp function
replace
return a > b with return a+b > b+a
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.