Fastest Algo to separate the 0s and 1s Suppose, I have an array of length 100.
I have 0s at some positions and 1s at some other positions.
What is the fastest method by which I can separate the 0s and 1s, so that we get all the 0s at the beginning and all the 1s at the remaining positions / vice-versa?
i=0, j=size(ar)-1;
while(true)
   increase i to position of first 1;
   decrease j to position of first 0;
   if(i&gt;=j) break;
   ar[i]=0, ar[j]=1;