Giving WA in 3/4 test cases

why is it giving WA on 3/4 test cases?

The logic that you used for k < a is wrong. Suppose we take the first sample test case, with a minor change of k = 1, then you’ll get the answer as 1 4 3 2 5 whereas it should be 5 4 1 2 3
You are swapping arr[i] and arr[a-arr[i]], whereas you should find (a-i) in the array and swap it with the element as ith position. Also in the if condition it should be k > 0, not k>=0.

I have commented out your mistaken part and written the correct one. Try analysing your mistakes once again.

Please feel free to reach out if you have any other doubts.