python3 Solution
\n\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        n=len(nums)\n        i=nums.index(1)\n        j=nums.index(n)\n     
\n```\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        n=len(nums)\n        i=nums.index(1)\n        j=nums.index(n)\n        ans=i+n-1-j-(i>j)\n        return ans\n```
['Python', 'Python3']