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;
}