GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers
Problem :- Largest Number formed from an Array .
Submit Your Solution :- Click Here
Solution :-
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int myCompare(string X, string Y)
{
string XY = X.append(Y);
string YX = Y.append(X);
return XY.compare(YX) > 0 ? 1: 0;
}
void printLargest(vector<string> arr)
{
sort(arr.begin(), arr.end(), myCompare);
for (int i=0; i < arr.size() ; i++ )
cout << arr[i];
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,i;
cin>>n;
vector<string> arr(n);
for(i=0;i<n;i++)
cin>>arr[i];
printLargest(arr);
cout<<endl;
}
return 0;
}
Output:-
0 Comments: