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.
Answers
Answered by
0
Answer:
It depends on if n is an even number or an odd number. If n is an even number, then the minimum number of swaps will = n%2.
If n is an odd number, then the number of swaps will = ((n+1)%2)-2
Explanation:
Similar questions