Help me in solving MAXDISTPERM problem

My issue

I understood the approach of most people who are just starting the second array from the middle. I want to ask that what is the problem in writing the second array in reverse order. I did this with many values of n and always found out that the sum is same in both my way and in the way most people had done. Someone please explain me this as it is very frustrating thing. Thanks

Problem Link: https://www.codechef.com/problems/MAXDISTPERM

distance is min abs(A[i]-B[i])for all i
in your case the distance will be 0 for odd and 1 for even
but in the question we have to output the premutation having maximum distance

let testcase n=3
1 2 3
3 2 1
2 0 2 – distance
distance =0
1 2 3
3 1 2
2 1 1 – distance
distance =1

1 Like