Easy java fast || Brute force
\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n int count=0;\n        if(nums[0]==1&& nums[nums.length-1]==nums.length){\n            
```\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n int count=0;\n        if(nums[0]==1&& nums[nums.length-1]==nums.length){\n            return 0;\n        }\n        int indst=0;\n        int indend=0;\n        for(int i=0;i<nums.length;i++){\n            if(nums[i]==1){\n                indst =i;\n            }\n            if(nums[i]==nums.length){\n                indend=i;\n            }\n        }\n        if(indst>indend){\n            count+=indst+(nums.length-2-indend);\n        }\n        else{\n            count+=indst+nums.length-1-indend;\n        }\n        return count;\n    }\n}\n```
['Array', 'Java']