From SO.
You are given an array with positive and negative integers. Write a function to change the elements order in the array such that negative integers are at the beginning, the positive integers are at the end and two integers that have the same sign don't change order.
Example:
- Input 1,7,-5,9,-12,15
- Output -5,-12,1,7,9,15
- Input 1,-2,-1,2
- Output -2, -1, 1, 2
Constraints: O(n) time limit and O(1) extra memory.