Challenge: Rearrange Positive & Negative Values

Try to solve the Rearrange Positive & Negative Values problem.

We'll cover the following

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}
  • 10510^{-5} \leq arr.[i] 105\leq 10^{5}

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.