Easy solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int semiOrderedPermutation(vector<int>& nums) {
        int n=nums.size();
        int l=find(nums.begin(),nums.end(),1)-nums.begin(),r=find(nums.begin(),nums.end(),n)-nums.begin();
        if(l<r)
            return l+(n-1-r);
        return l+(n-1-r)-1;
    }
};
```
['C++']