Interview Question

Software Engineer Interview San Jose, CA

An array contains some random positive and negative

  numbers. Arrange array elements such that all positive elements are on left side, don't care about negative elements. Number of operations allowed - O(n)
Answer

Interview Answer

1 Answer

0

This is a job for descending quicksort. Append 0 to the array and set it as the pivot and all values greater than 0 will end up on the left side after 1 iteration.

avidprog on Sep 3, 2012

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up