If k>n the answer is different from mine

the last 2 element should flip according to remaining k is even or odd
// if(k%2==1){
// int temp=arr[n-1];
// arr[n-1]=arr[n-2];
// arr[n-2]=temp;
// }

but the answer doesnt takes this in concern

thats not true
suppose you get a permutation in decreasing order in 5 swaps and k is 6(which is even)
you still need to swap the last 2 elements to complete k swaps

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.