ITGUY30 - Editorial

Problem: Contest Page | CodeChef

DIFFICULTY:

EASY.

PROBLEM:

Cheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3]… and so on…, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and so on… Chef accepts the challenge, chef starts coding but his code is not compiling help him to write new code.

Program:

#include<bits/stdc++.h>
using namespace std;
int main()
 {
	//code
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
   	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);
   		for(int i=1;i<n;i+=2)swap(arr[i],arr[i-1]);
   		for(int i=0;i<n;i++)cout<<arr[i]<<" ";
   		
   	}
}