Solution in C
Approach
Iterate through the array to find the index of 1and index of last element.
Compare the indices "a" and "b" to determine if they are in the correct orde
# Approach
- Iterate through the array to find the index of `1`and index of last element.
- Compare the indices "a" and "b" to determine if they are in the correct order `(a < b)`
- If 1 is before numsSize, the number of swaps is the sum of "a" and the distance from "b" to the end of the array.
- If 1 is after numsSize, subtract one extra swap to avoid double-counting.
- The function returns the calculated number of swaps.
# Code
```c []
int semiOrderedPermutation(int* nums, int numsSize) {
    int a, b;
    for (int i = 0; i < numsSize; i++) {
        if (nums[i] == 1)
            a = i;
        if (nums[i] == numsSize)
            b = i;
    }
    if (a < b)
        return a + ((numsSize - 1) - b);
    return a + (((numsSize - 1) - b)) - 1;
}
```
['Array', 'C']