Search⌘ K

Solution: Rearrange Positive & Negative Values

Explore how to rearrange an array so all negative numbers appear on the left and all positives on the right. Understand two Java-based methods: one using extra space with an auxiliary array, and another performing the rearrangement in-place. Learn their time and space complexities to optimize your array manipulation skills.

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}
...