Implementation
def segregate(a)
left=0
right=a.length-1
while left<right
#Increment left index while we see 0 at left
while a[left]== 0
left+=1
end
#Decrement right index while we see 1 at right
while a[right]==1
right-=1
end
#Exchange arr[left] and arr[right]
if left<right
a[left],a[right]=a[right],a[left]
left+=1
right-=1
end
end
return a
end
segregate([1,0,1,1,0,0]) # => [0, 0, 0, 1, 1, 1]