Yeah, you are right. And the setter also has given the solution in the same format as you said.
My solution is bit different, and I have used this format to give the solution:
first sort the array in increasing order.
if n is odd
arr[n//2], arr[0], arr[n//2 +1], arr[1], arr[n//2 +2], arr[2], arr[n//2 +3], arr[3] . . . , arr[n-1]
else if n is even
arr[n//2], arr[0], arr[n//2 +1], arr[1], arr[n//2 +2], arr[2], arr[n//2 +3], arr[3] . . .
@aryan12@vijju123
please have a look into it… I have explained the question and my logic in the comment above… I am not able to figure out the reason for WA verdict…
just sort array in ascending order and print odd index element first and even index element afterward
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define list vector<ll>
#define pb push_back
#define llist vector<vector<ll>>
#define len size()
#define queue queue<ll>
#define pqueue priority_queue<ll>
#define mod 1000000007
#define endl '\n'
int main(int argc, char const *argv[])
{
IOS
int t;
cin>>t;
while (t--){
int n;
cin>>n;
int arr[n];
for (int i=0; i<n; i++) cin>>arr[i];
sort(arr, arr+n);
int index=1;
while (index<n){
cout<<arr[index]<<" "<<arr[index-1]<<" ";
index+= 2;
}
if (n%2!=0) cout<<arr[n-1];
cout<<endl;
}
return 0;
}