A swap
means removing any element from the array and appending it to the back of the same array. Given an array of integers find the minimum number of swaps
needed to sort the array.
Example :
A[3]= 3 , 2 , 1
B[3]= 1, 2, 3
i=0 j=0
A[0]!=B[0]
So swap ++ ( Whenever you increment assume that A[i] is removed and appended at the end )
i++
Now i=1 j=0
A[1]!=B[0]
So swap++
i++
Now i=2 j=0
A[2]==B[0]
Now j++
i == n now and hence break the loop
No. of swaps = 2