➤ Problem Link : 1339B. Sorted Adjacent Differences
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll m =1000000007;
int main()
{
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
ll ans[n];
int k=n-1;
int i=0,j=n-1;
while(i<j)
{
ans[k--]=arr[j--];
ans[k--]=arr[i++];
}
if(i==j)
ans[0]=arr[i];
for(int i : ans)
cout<<i<<" ";
cout<<"\n";
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
