Solved using Conditional sort(using comparator function)


#1

int comp(string x,string y)
{
string XY,YX;
XY=x.append(y);
YX=y.append(x);

if(XY.compare(YX)>0)
return 1;
else
return 0;
}
string Solution::largestNumber(const vector &A) {
unordered_map<int,int>m;
for(int i{0};i<A.size();i++)
{
m[A[i]]++;
}
for(auto i=m.begin();i!=m.end();i++)
{
if(i->second==A.size())
{return to_string(i->first);
exit(0);}
}

string s;
vectorv;
for(int i{0};i<A.size();i++)
{
v.push_back(to_string(A[i]));
}
sort(v.begin(),v.end(),comp);
for(int i{0};i<v.size();i++)
{
s+=v[i];
}
return s;

}