My issue
I am failing this test case
1 2 3 4
4 3 2 1
Why is that. It is giving max distance
My code
# cook your dish here
for i in range(int(input())):
N=int(input())
l=[]
for i in range(1,N+1):
l.append(i)
print(*l)
pt=N//2
k=[]
for i in range(pt,N,1):
k.append(l[i])
for j in range(0,pt,1):
k.append(l[j])
print(*k)
Problem Link: Maximum Distance Permutations Practice Coding Problem
no it is not giving maximum distance
1 2 3 4
3 4 1 2
max distance is 2
I dont get it. What is maximun distance? Can you please elaborate?
Test case length of 4
1 2 3 4
4 3 2 1 (Output that your code gives)
Difference (Absolute difference)
3 1 1 3
Minimum of (3,1,1,3) is 1
But with [3,4,1,2], difference would be
1 2 3 4
3 4 1 2
Difference
2 2 2 2
Minimum of (2,2,2,2) is 2
Which is the maximum value that can be achieved
distance any two permutation is minimum value of abs(A[i]-B[i]) for 1<=i<=N
we have to find maximum distance between any two permutation
Your permutatio of N=4
1 2 3 4
4 3 2 1
distance = 3-2=1
and in my case
1 2 3 4
3 4 1 2
distance = 3-1=4-2=2
which is greater than 1
your permutation is not giving the maximum distance possible