Correctness Of Minimum Number Of Swaps To Sort An Array
The question is from here: https://www.geeksforgeeks.org/minimum-number-swaps-required-sort-array/ I will repeat it below: Given an array of n distinct elements, find the minimum number of swaps required to sort the array. Examples: Input : {4, 3, 2, 1} Output : 2 Explanation : Swap index 0 with 3 and 1 with 2 to form the sorted array {1, 2, 3, 4}. Input : {1, 5, 4, 3, 2} Output : 2 I have solved the problem by doing the following. Sorting the array (n log(n)) time Making a hash to keep track of the swaps required as I compare both the sorted array and the original array. This should be