X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Arranging the array
Basic Accuracy: 37.8% Submissions: 6578 Points: 1

You are given an array of size N. Rearrange the given array in-place such that all the negative numbers occur before positive numbers.(Maintain the order of all -ve and +ve numbers as given in the original array).
 

Example 1:

Input:
N = 4
Arr[] = {-3, 3, -2, 2}
Output:
-3 -2 3 2
Explanation:
In the given array, negative numbers
are -3, -2 and positive numbers are 3, 2. 

 

Example 2:

Input:
N = 5
Arr[] = {2, -4, 7, -3, 4}
Output:
-4 -3 2 7 4

 

Your Task:  
You don't need to read input or print anything. Your task is to complete the function Rearrange() which takes the array Arr[] and its size N as inputs and returns the array after rearranging with spaces between the elements of the array.


Expected Time Complexity: O(N. Log(N))
Expected Auxiliary Space: O(Log(N))

 

Constraints:
1 ≤ N ≤ 107
-1018 ≤ Elements of array ≤ 1018

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Arranging the array

Output Window