Solution: Rearrange Positive & Negative Values
Explore how to rearrange elements in an array so all negatives appear on the left and positives including zero on the right. Learn two effective C++ methods: using an auxiliary array and an in-place swap approach. Understand their time and space complexities to optimize your code for interviews.
Statement
Implement a function that rearranges elements in an array so that all negative elements appear to the left and all positive elements (including zero) appear to the right. It’s important to note that maintaining the original sorted order of the input array is not required for this task.
Constraints:
-
arr.length