Doubt in the logic of the problem

https://codeforces.com/problemset/problem/1372/C

here- https://ide.codingblocks.com/s/588906

here my program logic is that I have sorted the array then checked out if the both are equal then the ans is 0

then i have checked elementwise with the given array and the sorted array and then if they are the same I have incremented the count (the no of m=nos which are in there sorted position)
then the no of exchanges is count -1

Please tell me where my logic i s wrong and what should be the approach

hey @Somasree take reference from here
https://codeforces.com/blog/entry/79974

ok.can u plz tell me whats wrong in my approach

i haven’t seen it. try to figure out on your own once, as it’s a starting question of a contest so you will be able to do it.

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.