Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
int n;
while(t--){
cin>>n;
deque <int> drr;
int x;
for(int i = 0; i < n; i++){
cin>>x;
drr.push_back(x);
}
bool check = false;
for(int i = 0; i < n; i++){
check = !check;
if(check){
cout<<drr.front()<<" ";
drr.pop_front();
}
else{
cout<<drr.back()<<" ";
drr.pop_back();
}
}
cout<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
6
7
3 4 5 2 9 1 1
4
9 2 7 1
11
8 4 3 1 2 7 8 7 9 4 2
1
42
2
11 7
8
1 1 1 1 1 1 1 1
7
3 4 5 2 9 1 1
4
9 2 7 1
11
8 4 3 1 2 7 8 7 9 4 2
1
42
2
11 7
8
1 1 1 1 1 1 1 1
Output
3 1 4 1 5 9 2
9 1 2 7
8 2 4 4 3 9 1 7 2 8 7
42
11 7
1 1 1 1 1 1 1 1
9 1 2 7
8 2 4 4 3 9 1 7 2 8 7
42
11 7
1 1 1 1 1 1 1 1
Demonstration
Codeforcess Solution 1462-A A. Favorite Sequence ,C++, Java, Js and Python,1462-A,Codeforcess Solution