What's Wrong With My Code? Help

First Subtask Solution Accepted (AC).
Second Subtask Rejected (WA).
Please Help Me Find The Problem.
Problem Link: CodeChef: Practical coding for everyone
My Submission:
CodeChef: Practical coding for everyone
Here Is My Code:

for tc in range(int(input())):
	N, K = map(int, input().split(" "))
	if N - K >= 2:
		ans = ""
		L = [x for x in range(N, K, -1)]
		N = [x for x in range(1, K+1)]
		N.extend(L)
		for x in N:
			ans += str(x) + " "
		print(ans)
                #Tried Removing trailing Spaces
	else:
		print(-1)
		

There are 2 problems.
First, there is one more case N=K where answer is possible.
Second, reversing the remaining part doesn’t guarantee that Ai≠i
Try this example
N=8 K=5
Your answer,
1 2 3 4 5 8 7 6
But 7 is in its correct place which shouldn’t happen.

2 Likes

For k==n, there exists an answer. You are returning -1.

2 Likes

ThankS Very Much for The Quicl Reply

thank you for Explaining :smiley:

statement was wrong if else statement up