What's wrong here?

#include<bits/stdc++.h>
using namespace std;
bool compare(int &a,int &b)
{
string s1 = to_string(a);
string s2 = to_string(b);

int m1 = s1.size();
int m2 = s2.size();

int i = 0;
int j = 0;
while(i<(m1-1) || j<(m2-1))
{

	if(s1[i] != s2[j])
	{
		return s1[i]>s2[j];
	}
	if(i!=m1-1)
		i++;
	if(j!=m2-1)
		j++;
}
return s1[i]>s2[j];

}
int main() {
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int A[n];
for(int i = 0;i<n;i++)
{
cin>>A[i];
}

	sort(A,A+n,compare);

	for(int i = 0;i<n;i++)
	{
		cout<<A[i];
	}
}
return 0;

}

hello @alamsarfraz422

pls save ur code at cb ide and share its link with me

https://ide.codingblocks.com/s/475570 is it working?

try this case->
1
3
23 23 233

for this problem the logic is if a and b are two numbers then u can combine them in two ways either ab or ba right?
which ever combination give us maxium we will consider that order.
so just apply same logic in ur comparator and sort using this comparator

bool cmp(string a,string b){
return a+b > b+a;
} 

#include<bits/stdc++.h> using namespace std; bool compare(int &a,int &b) { string s1 = to_string(a); string s2 = to_string(b); return s1>s2; } int main() { int t; cin>>t; while(t–) { int n; cin>>n; int A[n]; for(int i = 0;i<n;i++) { cin>>A[i]; } sort(A,A+n,compare); for(int i = 0;i<n;i++) { cout<<A[i]; } cout<<endl; } return 0; }

Still its coming out wrong? why?? https://ide.codingblocks.com/s/475832

here it should be s1+s2 > s2+s1

Oh thanks!! it workss

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.