Not passing any of the testcases

I’m using the inbuilt greater<>() function as comparator. Sample input gives correct result but none of the test cases are passing

Lets see ! Cosider 2 nos 45 and 452 which can make 45245 and 45452 but in your code you are cosidering first one to be bigger use custom comperator instead and append one string after the other and check which one is greater.Hope it helps :slight_smile: :slightly_smiling_face:

#include
#include
#include
#include
using namespace std;

bool compare(string a,string b)
{
string ab = a.append(b);
string ba = b.append(a);
return ab.compare(ba)>0;
}

int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
vector a;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
a.push_back(s);
}
sort(a.begin(),a.end(),compare);

	for(int i=0;i<a.size();i++){
		cout<<a[i];
	}
	cout<<"\n";
}
return 0;

}
//Slight modification in your code

YES. Thank you so much! Great help