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