New update is available. Click here to update.

Last Updated: 3 Jul, 2021

Difficulty: Easy

```
Let the given array be [1,5,4,3,2] we swap index 1 with 4 i.e. 5 -> 2 and 2 with 3 i.e. 4 -> 3 to form the sorted array {1, 2, 3, 4, 5}.
```

```
The first line of input contains an integer ‘T’ representing the number of test cases. Then the test cases follow.
The first line of each test case contains an integer ‘N’ representing the size of the input array.
The second line of each test case contains the 'N' elements of the array separated by a single space.
```

```
For each test case, print a single line containing a single integer which represents the minimum no. of swaps required to sort the array.
The output for each test case is in a separate line.
```

```
You do not need to print anything; it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 100
1 <= N <= 1000
0 <= ARR[i] <= 10 ^ 9
Where 'ARR[i]' is the value of the input array elements.
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Maximum GCD

Posted: 8 Dec, 2022

Difficulty: Hard

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Sort 0s, 1s, 2s

Posted: 24 Dec, 2022

Difficulty: Easy

Popular Interview Problems: