semiOrderedPermutation: easy O(n) solution. BEAT 100%. ✅
IntuitionThe problem involves making the given permutation semi-ordered with a minimum number of adjacent swaps. By finding the positions of 1 and n, we can cal
# Intuition
The problem involves making the given permutation semi-ordered with a minimum number of adjacent swaps. By finding the positions of 1 and n, we can calculate the necessary swaps.

# Approach
1. Locate the positions of the numbers 1 and n in the permutation.
2. Calculate the number of swaps needed by considering their initial positions and the required final positions.
3. If the position of 1 is after n, decrement the position of 1 to account for their shift.
4. Sum the moves needed to place 1 at the start and n at the end.

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(1)

# Code
```c []
int semiOrderedPermutation(int* nums, int numsSize) {
    int indexOne, indexN;
    for(int i=0;i<numsSize;i++){
        if(nums[i]==1) indexOne=i;
        else if(nums[i]==numsSize) indexN=i;
    }
    if(indexOne>indexN) indexOne--;
    return indexOne + numsSize-1-indexN;
}
```
['Array', 'C', 'Simulation']