Code
#include<bits/stdc++.h>
using namespace std;
bool mycompare(string X, string Y)
{
string XY=X.append(Y);
string YX=Y.append(X);
return XY.compare(YX)>0?1:0;
}
void maximumNumber(vector st)
{
sort(st.begin(),st.end(),mycompare);
for(int i=0;i<st.size();i++)
{
cout<<stoi(st[i]);
}
}
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int m;
vector sp;
cin>>m;
while(m–)
{
int temp;
cin>>temp;
string temp2=to_string(temp);
sp.push_back(temp2);
}
maximumNumber(sp);
}
return 0;
}
Sample case is working but other test cases failed
Firstly, the numbers can be very large so do not convert it to integers using stoi. Print the output in string format itself.
Also after printing the result of each test case, include an endl.
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.