9int minSwaps(
int arr[],
int n) {
13 std::pair<int, int> *arrPos =
new std::pair<int, int>[n];
14 for (
int i = 0; i < n; i++) {
15 arrPos[i].first = arr[i];
22 std::sort(arrPos, arrPos + n);
26 std::vector<bool> vis(n,
false);
32 for (
int i = 0; i < n; i++) {
35 if (vis[i] || arrPos[i].second == i)
52 ans += (cycle_size - 1);
64 int arr[] = {6, 7, 8, 1, 2, 3, 9, 12};
65 int n = (
sizeof(arr) /
sizeof(int));
66 std::cout << minSwaps(arr, n);