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. Find the minimum number of swaps required to sort the array in ascending order.
arr = [7, 1, 3, 2, 4, 5, 6]
Perform the following steps:
It took 5 swaps to sort the array.
Complete the function minimumSwaps in the editor below.
minimumSwaps has the following parameter(s):
int arr[n]: an unordered array of integers
Returns
int: the minimum number of swaps to sort the array
Input Format
The first line contains an integer, n , the size of arr.
The second line contains n space-separated integers arr[i]