Easy, Clean, Python3 Solution 🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nIt is a very straightforward approach, we can simply, easily simulate it.\n\n# Approach
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is a very straightforward approach, we can simply, easily simulate it.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nkeep track of the given indices of 1 and the last element. Perform swaps and calculate swaps to find the required answer.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ where n is the size of nums\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n    def semiOrderedPermutation(self, nums: List[int]) -> int:\n        n = len(nums)\n        reqd = {1:0, n:(n-1)}\n        given = {1:0, n:0}\n        for i in range(n):\n            if nums[i] == 1:\n                given[1] = i\n            if nums[i] == n:\n                given[n] = i\n        if given == reqd: return 0\n        if given[n] < given[1]:\n            return n-1-given[n]+given[1]-1\n        else:\n            return given[1] + (n-1) - given[n]\n            \n```
['Array', 'Hash Table', 'Simulation', 'Python3']