Easy Solution in C
Code

# Code
```c []
int semiOrderedPermutation(int* nums, int numsSize) {
    if(nums[0] == 1 && nums[numsSize - 1] == numsSize) return 0;

    int posOne = -1;
    int posSize = -1;
    for(int i=0; i<numsSize; i++){
        if(nums[i] == 1) posOne = i;
        else if(nums[i] == numsSize) posSize = i;

        if(posOne != -1 && posSize != -1) break;
    }
    return ((posOne < posSize) ? (posOne - posSize + numsSize - 1) : (posOne - posSize + numsSize - 2));
    
}

// [2, 4, 1, 3] 
// ee = 1
// ss = 2
```
['C']