Positive and negative elements
Basic Accuracy: 48.75% Submissions: 11112 Points: 1

Given an array containing equal number of positive and negative elements, arrange the array such that every positive element is followed by a negative element.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting size of array and the second line contains N space separated elements.

Output:
For each test case, in a new line print the arranged array.

Constraints:
1 <= T <= 300
2 <= N <= 105

-105 <= A[i] <= 105

Example:
Input:

2
6
-1 2 -3 4 -5 6
4
-3 2 -4 1
Output:
2 -1 4 -3 6 -5
2 -3 1 -4

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.