This was the question- CodeChef: Practical coding for everyone
I did this but still it was segmentation error, don’t know why.
#include
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n;
cin>>n;
int num;
int sum;
vectorleft;
vectorleft_ans;
vectorright;
vectorright_ans;
for(int i=0; i<n; i++){
cin>> num;
sum = num*(num-1);
sum= sum/2;
if(sum%2!=0 || num%2!=0){
cout<<"NO"<<endl;
}else{
for(int i=0; i<num/4; i++){
left_ans.push_back(num-num/4+i+1);
right_ans.push_back(num/4+i+1);
}
for(int j=0; j<num/4; j++){
left_ans.push_back(j+1);
right_ans.push_back(num/2+1+i);
}
}
for(int i=0; i<num/2; i++){
if(i!=(num/2)-1){
cout<<left_ans[i]<<" ";
}else{
cout<<left_ans[i]<<endl;
}
}
for(int i=0; i<num/2; i++){
cout<<right_ans[i]<<" ";
}
}
return 0;
}