Array of alternate +ve and -ve no.s
Submissions: 15327   Accuracy:

32.07%

  Difficulty: Basic   Marks: 1

Given an unsorted array of positive and negative numbers. Your task is to create an array of alternate positive and negative numbers without changing the relative order of positive and negative numbers.

Input:
First line of input contains an integer T denoting the number of test cases. For each testcase, first line contains N, size of array. The subsequent line contains N array elements.

Output:
Print the modified array.
Note: Array should start with positive number.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 107
-106 ≤ a[] ≤ 107

Example:
Input:
1
9
9 4 -2 -1 5 0 -5 -3 2

Output:
9 -2 4 -1 5 -5 0 -3 2


 

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.