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

**Input:**

The first line consists of an integer **T** denoting the number of test cases. T testcases follow. Each test case contains two lines of input. The first line contains the size of the array denoted by **N**. Then in the next line are N space separated elements of the array.

**Output:**

For each test case, print the array after rearranging with spaces between the elements of the array.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{7}

-10^{18} <= Elements of array <= 10^{18}

**Example:**

**Input:**

2

4

-3 3 -2 2

5

2 -4 7 -3 4

**Output:**

-3 -2 3 2

-4 -3 2 7 4

Explanation:

Testcase 1: In the given array, negative numbers are -3, -2 and positive numbers are 3, 2.

Author: Ayush jha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.