Please help me understand the problem with my solution

in April Lunchtime SHUFFLE

https://www.codechef.com/viewsolution/32262703

```
for _ in range(int(input())):
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=sorted(a)
#print(x)
for i in range(n):
if (i+k<n):
if (a[i]>a[i+k]):
temp=a[i+k]
a[i+k]=a[i]
a[i]=temp
if (x==a):
print('yes')
else:
print('no')
```

I think you’re missing the fact that you can swap elements more than once.

What you’re doing here is like one pass of bubble sort, which is definitely not guaranteed to sort the whole array.

In case you don’t understand, here is a test case on which your code should fail

```
1
3 1
3 2 1
```

Thank you @psaini72 again for helping me out. I got the fix for my problem

```
for _ in range(int(input())):
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=sorted(a)
#print(x)
for j in range(n):
for i in range(n):
if (i+k<n):
if (a[i]>a[i+k]):
temp=a[i+k]
a[i+k]=a[i]
a[i]=temp
#print(a)
if (x==a):
print('yes')
else:
print('no')
```

But as there is a time limit it isn’t working so I would proceed with the explanation in the editorial. Thank you so much.