One Line
\n# Complexity\n- Time complexity: O(N) \nNotice here we used the := operator. \n- Space complexity: O(1)\n\n# Code\n```python3 []\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        return max(-1 + 2 * ((i := min((t for t in enumerate(nums)), key=lambda x:x[1])[0]) - (j := max((t for t in enumerate(nums)), key=lambda x:x[1])[0])), 0) + min(i, j) + len(nums) - max(i, j) - 1\n```
['Python3']