Interview Question
here it is O(n/2) = O(n)
def segBinary():
e = [0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0]
j = len(e)-1
for i in range(0, len(e)/2):
if e[i] == 1:
while e[j] != 0:
j-=1
one = e[i]
e[i] = e[j]
e[j] = one
print e
Count the number of zeros..fill the array with count of zeros and remaining with 1's..
- Musheka January 14, 2010