This is one of an interview question which I had recently. I would like to know others perception of approach for this problem.
Question:
Yo
Easy:
function sort(array):
new_array = new Array(array.length)
x = 0
for(i : array): if(i): new_array(x++) = 1
return new_array
And if you actually want to have the same 1s and 0s:
function sort(array):
new_array = new Array(array.length)
x, y = 0, array.length / 2
for(i : array):
if(i): new_array(x++) = i
else: new_array(y++) = i
return new_array