Java || Beats 100%
\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int pos1 = 0;\n        int pos2 = 0;\n        \n        for(int i = 0; i < nums
```\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int pos1 = 0;\n        int pos2 = 0;\n        \n        for(int i = 0; i < nums.length; i++) {\n            if(nums[i] == 1)\n                pos1 = i;\n            else if(nums[i] == nums.length)\n                pos2 = i;\n        }\n        \n        // if 1 is present at a position greater than position of n\n        // then one swap will be common\n        if(pos1 > pos2)\n            pos2++;\n        \n        return pos1 - 0 + nums.length - 1 - pos2;\n    }\n}\n```
['Java']