TC - nlogn SC- o(1) extra space

google
programming
amazon
interview-questions
Tags: #<Tag:0x00007f242f5b2c78> #<Tag:0x00007f242f5b2a70> #<Tag:0x00007f242f5b2728> #<Tag:0x00007f242f5b2368>

#1
> bool compare(int a, int b){
>     string x = to_string(a);
>     string y = to_string(b);
>     return ((x+y)>(y+x));
> }
> 
> string Solution::largestNumber(const vector<int> &A) {
>     vector<int> vec;
>     
>     for(int i=0; i<A.size(); ++i) vec.push_back(A[i]);
>     
>     int n = vec.size();
>     // sort 
>     sort(vec.begin(), vec.end(), compare);
>     int count=0;
>     string ans;
>     
>     for(int i=0; i<n; ++i)
>     {
>         //this is for edge case when array element are all  zero
>         if(vec[i]==0) count++; 
>         ans+=to_string(vec[i]);
>     }
>     
>     if(vec.size()==count) return ans="0";
>     else return ans;
> }