Easy peasy 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 anchuu=0;
        // taking 1 to 0th index
        while(nums[0]!=1)
        {
            for(int i=1;i<n;i++)
            {
                if(nums[i]==1)
                {
                    swap(nums[i],nums[i-1]);
                    anchuu++;
                    break;
                }
            }
        }
        //taking n to n-1th index
        while(nums[n-1]!=n)
        {
            for(int i=1;i<n-1;i++)
            {
                if(nums[i]==n)
                {
                    swap(nums[i],nums[i+1]);
                    anchuu++;
                    break;
                }
            }
        }
        return anchuu;
    }
};
```
['C++']