Search⌘ K
AI Features

Solution: Rearrange Positive & Negative Values

Explore how to rearrange elements in an array so all negative numbers precede positive and zero values without preserving order. Understand two approaches: one using an auxiliary array and another performing in-place swaps, both with O(n) time complexity. This lesson helps you implement efficient array manipulation techniques relevant for coding 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:

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