Question: Airtel, Online Assessment Questions (13th September 2023) | Rearrange Array to give the largest Value
0
Entering edit mode

ADD COMMENTlink 14 months ago Delta 2.9k
0
Entering edit mode


Question solution

bool compare(string &a,string &b)
{
    //return a>b;
    string x=a+b;
    string y=b+a;
   // cout<<a<<" "<<b<<" "<<x<<" "<<y<<endl;
    return x>y;
  /*  cout<<a<<" "<<b<<endl;
  if(a.length()==b.length())
    return a>b;
else if(a.length()<b.length())
{

    int x=a.length()-1;
    for(int i=0;i<=x;i++)
    {
        if(a[i]!=b[i])
        {
            if(a[i]>b[i])
            return a>b;
            else
            return b>a;
        }
    }
   for(int i=a.length();i<b.length();i++)
   {
    if(a[x]>b[i])
        return a>b;
   }
   return b>a;
}
else
{
     int x=b.length()-1;
     for(int i=0;i<=x;i++)
    {
        if(a[i]!=b[i])
        {
            if(a[i]>b[i])
            return a>b;
        else
            return b>a;
        }
    }
   for(int i=b.length();i<a.length();i++)
   {
    if(b[x]>a[i])
        return b>a;
   }
   return a>b;
}*/
        
}

void solve()
{
int n;
cin>>n;
vector<int> v(n);

vector<string> s;
f(i,n)
{
cin>>v[i];
s.pb(to_string(v[i]));
}
sort(s.begin(),s.end(),compare);
cout<<s<<endl;
}

 

ADD COMMENTlink 14 months ago suryansh jaiswal • 370

Login before adding your answer.

Similar Posts
Loading Similar Posts