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
In abstract terms, you could use a modified insertion sort, swapping all zero values to the right and all one values to the left. That would have complexity greater than O(n), however.
I'm slightly confused why ordering matters, as posted previously, bytes are indistinguishable.
EDIT: The new example helps. The benefit of my algorithm, even though it's slower than linear time in the worst case, is that it's only O(n) in memory usage. Since the ones and zeros are only keys for larger objects (which may be arbitrarily large), memory may be a concern.