Easy To Read | Python Solution
Code\npython3 []\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        min_pos = max_pos = -1\n        for i in range(len(num
# Code\n```python3 []\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        min_pos = max_pos = -1\n        for i in range(len(nums)):\n            if nums[i] == 1:\n                min_pos = i\n            if nums[i] == len(nums):\n                max_pos = i\n            if min_pos != -1 and max_pos != -1:\n                break  \n        \n        ans = min_pos + (len(nums) - 1 - max_pos)\n        return ans - 1 if min_pos > max_pos else ans\n```
['Python3']