Python 3   ||   2 lines,  w/ brief explanation   ||   T/S: 99% /  63%
Here\'s the plan:\n\n- We determine the indices mnandmxof two numbers being migrated to the ends of the list.\n- We count the number of steps required to move e
Here\'s the plan:\n\n- We determine the indices `mn`and`mx`of two numbers being migrated to the ends of the list.\n- We count the number of steps required to move each, which are `mn` and `n-mx-1`. \n- We check whether `mn > mx`, in which case the two migrations share a step and we then correct by decrementing the sum by one.\n\n- We return this sum.\n```\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        \n        mn, mx = nums.index(1) , nums.index(n:= len(nums))     \n        return mn - mx + n - 1 - (mn > mx)\n```\n[https://leetcode.com/problems/semi-ordered-permutation/submissions/1440532226/](https://leetcode.com/problems/semi-ordered-permutation/submissions/1440532226/)\n\n\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(1), in which *N* ~`len(nums)`.
['Python3']