Skip to content

Tag: optimization

Min swaps for sorting list of consecutive integers

The problem: You are given an unordered array consisting of consecutive integers [1, 2, 3, …, n] without any duplicates. You are allowed to swap any two elements. You need to find the minimum number of swaps required to sort the array in ascending order. My solution/issue: My code does what it is suppos…