Solution in C
Code

# Code
```c []
int semiOrderedPermutation(int* nums, int numsSize) {
    int n1=-1,n2=-1;
    for(int i=0;i<numsSize;i++)
    {
        if(nums[i]==1) n1=i;
        else if(nums[i]==numsSize) n2=i;
        if(n1!=-1 && n2!=-1) break;
    }
    return ((n1<n2) ? (n1 - n2 + numsSize-1) : (n1 - n2 + numsSize-2));
    
}
```
['C']