Skip to content

Instantly share code, notes, and snippets.

@mk6619
Created December 4, 2019 12:17
Show Gist options
  • Select an option

  • Save mk6619/c92e8c73eaf5ccad620bd8d81cc63eb3 to your computer and use it in GitHub Desktop.

Select an option

Save mk6619/c92e8c73eaf5ccad620bd8d81cc63eb3 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
//code
int testCases;
cin>>testCases;
for(int i = 0 ; i < testCases; i++) {
int n;
cin>>n;
int arr[n];
for(int j =0 ; j < n ; j++) {
cin>>arr[j];
}
int arr_n[n];
int left =0, right= n-1;
int index = 0;
while(index <n) {
if(index%2==0) {
arr_n[index] = arr[right];
right--;
} else {
arr_n[index] = arr[left];
left++;
}
index++;
}
for(int j =0 ; j < n ; j++) {
cout<<arr_n[j]<<" ";
}
cout<<"\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment