Search⌘ K
AI Features

Solution: Rearrange Positive & Negative Values

Explore how to rearrange an array so that all negative values appear to the left and positive values, including zero, to the right. Understand two approaches: one using extra space with an auxiliary array and an in-place method without additional memory. Learn to analyze their time and space complexities for optimized C++ coding practices.

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:

  • 11 \leq arr.length 103\leq 10^{3}
...