You are given an array of n distinct integers. A swap is interchanging the value of two positions in the array. What is the minimum number of swaps required to sort the array?
For example: If the array is [2,1,3], we need only 1 swap (swap 1 and 2). If the array is [2,3,1], we need 2 swaps (swap 2 and 3, then swap 1 and 3).
- via Stack Overflow