Search⌘ K

Solution: Rearrange Positive & Negative Values

Explore techniques to rearrange array elements so that negative values are positioned to the left and positive values to the right. Understand two approaches: using auxiliary arrays and performing in-place swaps. Learn how to implement these solutions in JavaScript with a focus on time and space complexity to optimize your code.

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