On November 12, as we celebrate technological progress and problem-solving in tech, your task is to work with a sorting-related challenge. Given an array of distinct integers, determine the minimum number of swaps required to sort the array in ascending order. In each swap, you can exchange the positions of any two elements in the array.
For the input:
[4, 3, 1, 2]
One way to sort the array is:
This requires a total of 3 swaps, so the output should be 3
.
Below is some language-agnostic starter code to help you begin your solution.