Make equal elements Array: Easy Solution C++

int Solution::solve(vector &a, int b) {

int n=a.size();

map<int,int>mp;

for(int i=0;i<n;i++)

{

    mp[a[i]]++;

}

vector<int>v;

for(auto i:mp)

{

    v.push_back(i.first);



}

if(v.size()==1){return 1;}

else if(v.size()==2)

{

    if(v[0]+b==v[1] || v[0]==v[1]-b){return 1;}

}

else{

    if(v[0]+b==v[1] && v[1]==v[2]-b){return 1;}

}



return 0;

}

Click here to start solving coding interview questions