I am getting 3 test cases failed

I have coded the solution and I have tried various combinations other than than the sample test case and I am getting the correct answer but I am not able to figure out where my code is wrong.So please help me out.
My code is:https://ide.codingblocks.com/s/613552

Hi Kartik
ur code is giving wrong o/p only
consider test case
9 3
9 4 1 7 8 3 2 6 5
ur o/p --> 7 8 3 2 6 3 9 4 1
expected o/p --> 1 4 9 3 8 7 5 6 2

refer this code https://ide.codingblocks.com/s/613945

Hi Kartik
so sry i misread the ques… refer this https://ide.codingblocks.com/s/614001

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.