# SHUFFLE problem my solution

Hello guys here is my solution for problem SHUFFLE but I got wrong answer.Can you tell me what is wrong with my code? I basically swap the element i with i+k and then check the elements before i for placing the element in its correct place.

``````#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
long long T,N,a[100000],K,test;
bool flag;
cin>>T;
while(T--){
flag=true;
cin>>N>>K;
for(int i=0;i<N;i++){
cin>>a[i];
}
for(int i=0;i<N-K;i+=K){
if(a[i]>a[i+K]){
test=a[i+K];
a[i+K]=a[i];
a[i]=test;
for(int j=i;j>=K;j-=K){
if(a[j]<a[j-K]){
test=a[j-K];
a[j-K]=a[j];
a[j]=test;
}
}

}

}

for(int i=0;i<N-1;i++){
if(a[i]>a[i+1]){

flag=false;
break;
}

}
if(flag && N>K )
cout<<"yes"<<endl;
else
cout<<"no"<<endl;

}

return 0;
}``````

Hi, @subhanhack I think you only check if the elements are sorted in ascending order but this isn’t the only case when the answer will be “yes”. If you read the question properly it is told that they need element in sorted order but not necessarily in ascending order it can be in desending order also so you need to check also for that.

In the comment problem owner said it must be ascending order so there is no need to check descending