Array Manipulation

3.9

8 votes
Hard
Problem

Jack was bored from his usual routine of studies and he wants to solve a problem on Hackerearth.

The problem is as follows:-

Given a number N denoted the elements in an array.He wants to arrange the elements of an array such that odd positions have sorted elements in ascending order and even positions have sorted elements in descending order. for example, if we have 1 2 3 4 5 then the result will be 1 5 2 4 3.

Please write the code for this problem

Input Input description.

  • The first line of the input contains an integer T denoting the number of test cases.
  • The description of T test cases follows.
  • First line of each test case contains N number of elements in an array.
  • Second line contains N space separated integers A1, A2, ..., AN.

Output

  • Print array in desired order.

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 1000000
  • 1 ≤ Ai ≤ 100000000
Time Limit: 10
Memory Limit: 256
Source Limit:
Editor Image

?