Simple O(N) solution in C++ for this


#1

nt n=A.size();int r=0, w=0, b=0;
for(int i=0;i<n;i++)
{
if(A[i]==0) r++;
else if(A[i]==1) w++;
else if(A[i]==2) b++;
}

for(int i=0;i<n;i++)
{
if(i<r) A[i]=0;
else if(i<(r+w)) A[i]=1;
else A[i]=2;
}