minimumm sort tryed 1

minimumm sort tryed

int minimumSwaps(vector arr) {
    
    int i,c=0,n=arr.size();
    for(i=0;i

Here is what the above code is Doing:
1. We are iterating over the array and checking if the element is at its correct position.
2. If it is at its correct position, we continue.
3. If it is not at its correct position, we swap it with the element at its correct position.
4. We decrement i by 1 so that we can check if the swapped element is at its correct position.
5. We increment the count of swaps by 1.
6. We return the count of swaps.

Similar Posts