Equalize the Array

 https://www.hackerrank.com/challenges/equality-in-a-array/problem

int equalizeArray(vector<int> a) {
sort(a.begin(),a.end());
    int max=a[0],c=1,maxi=1;
    for(int i=1;i<a.size();i++){
        if(a[i]==max){
            c++;
            if(c>maxi){
                maxi=c;
            }
        }
        else{
            max=a[i];
            c=1;
        }        
    }
return a.size()-maxi;
}

 

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!