Easy C++ Solution
\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n        int idx,idx2;\n        for(int i = 0;i<nums.size();i++){\n            
```\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n        int idx,idx2;\n        for(int i = 0;i<nums.size();i++){\n            if(nums[i]==1) idx=i;\n            if(nums[i]==nums.size()) idx2=i;\n        }\n        int ans=0;\n        for(int i = idx;i>=0;i--){\n            if(i==0) break;\n            swap(nums[i],nums[i-1]);\n            ans++;\n        }\n        for(int i = 0;i<nums.size();i++){\n            if(nums[i]==nums.size()) idx2=i;\n        }\n        for(int i = idx2;i<nums.size();i++){\n            if(i==nums.size()-1) break;\n            swap(nums[i],nums[i+1]);\n            ans++;\n        }\n    return ans;\n    }\n};\n```
['C']