As nothing is written about space complexity, I am assuming that we can
take extra space.

Take a temporary array of length n.

1. Maintain a counter for the length of temporary array filled till now.

2. Traverse the given array. If value contained is negative insert it in
new array and update counter. After complete traversal all negative values
will be in the temporary array.

3. Traverse again the given array. Repeat step 2 but this time for positive
numbers.

Finally temporary array contains the required answer. If required copy it
into original array.

As this approach takes max. 3 traversals so its complexity is O(n).

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to